views:

354

answers:

3

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 text ${ 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();
    }
A: 

Check out this link : http://dotnetslackers.com/articles/aspnet/Installing-the-Spark-View-Engine-into-ASP-NET-MVC-2-Preview-2.aspx

ali62b
There is no usage of HTML forms in that article.
rotary_engine
A: 

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.

blue_fenix