开发者

Example of using HTML forms with Sparkview engine on ASP.NET MVC2

开发者 https://www.devze.com 2022-12-17 03:40 出处:网络
I am playing with Sparkview 1.0 on ASP.NET 4.0 with MVC2. Trying to create a simple HTML form. When the form loads, it renders as expected. Click Save button on the form, the model validates, returns

I am playing with Sparkview 1.0 on ASP.NET 4.0 with MVC2. Trying to create a simple HTML form.

When the form loads, it renders as expected. Click Save button on the form, the model validates, returns an error about length of field (expected) but then the !{ Model.Name } tag gets rendered as the t开发者_StackOverflow中文版ext ${ Model.Name } rather than the actual expected output of "test blah blah".

Where can I find an example of creating HTML forms using the HTML helpers with Sparkview?

!{ Model.Name }
${ Html.ValidationSummary("Edit was unsuccessful. Please correct the errors and try again.") }

# Html.BeginForm();

    <fieldset>
        <legend>Fields</legend>
        <p>
            <label for="Name">Name:</label>
            !{ Html.TextBox("Name", Model.Name) }

        </p>
        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>

# Html.EndForm();

And here is the controller method:

    [HttpPost]
    public ActionResult Add(Project project)
    {

        if(ModelState.IsValid)
        {
            // save to db
            Response.Redirect("/");
        }
        ViewData["Model"] = project;
        return View();
    }


Model is a special name in Spark, it represents a strongly typed model for your view.

Therefore, you can either change the name of your dictionary key to something other than Model (call it ViewData["SuperModel"]:) or simply return the strongly typed viewresult overload of the view method.

0

精彩评论

暂无评论...
验证码 换一张
取 消