<%= Html.Hidden("Pro...">

How do we present the following snippet of view code in a Spark view?

<% using (Html.BeginForm("AddToCart", "Cart")) { %>        
    <%= Html.Hidden("ProductID", pr.ProductID) %>
    <%= Html.Hidden("returnUrl", ViewContext.HttpContext.Request.Url.PathAndQuery) %>
    <input type="submit" value="+ Add to cart" />
 <% } %> 

I am currently using

# using (Html.BeginForm("AddToCart", "Cart")) {
    ${Html.Hidden("ProductID", pr.ProductID)}
    ${Html.Hidden("returnUrl", ViewContext.HttpContext.Request.Url.PathAndQuery)}
    <input type="submit" value="+ Add to cart" />
 #} 

Is it correct? any better approach?

+3
source share
2 answers

Now with the latest version of Spark (v1.5), a new version has appeared with the new Bindings feature. You can read my blog post here , which has an example Html form for you.

Basically, your html form code in your Spark view ends correctly with the MVC Html Form Helper, but it looks amazing like this:

<Form class="form-default">
    <ValidationSummary Message="Login was unsuccessful.
    Please correct the errors and try again." ExcludePropertyErrors="true" />
    <div class="editor-label">
         <Label For="UserName" />
    </div>
    <div class="editor-field">
         <TextBox For="UserName" /><ValidationMessage For="UserName"/>               
    </div>
    <div class="editor-label">
         <Label For="Password" />
    </div>
    <div class="editor-field">
         <Password For="Password" /><ValidationMessage For="Password" />
    </div>
    <div class="editor-label">
        <CheckBox For="RememberMe" />
        <Label For="RememberMe" />
    </div>
    <input type="submit" value="Log On" />
</Form>

You can also see a draft sample code that uses it in the source code base here .

, ,
Rob

+1

, , . :

#Html.BeginForm("AddToCart", "Cart");
...
#Html.EndForm();
0

Source: https://habr.com/ru/post/1731312/


All Articles