2010-02-04 17 views
3
<% 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" /> 
<% } %> 

目前我使用我們如何在Spark視圖中表示以下一段視圖代碼?

# 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" /> 
#} 

這是正確的方式?任何更好的方法?

回答

0

我假設你指的是如何處理表單標籤。你可以這樣做:

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

現在有一個更好的方式與最新版本的Spark(v1.5)使用新的Bindings功能。你可以閱讀my blog post on it here,它有一個Html窗體的例子給你。

基本上在你的星火看你的HTML表單代碼最終使用MVC HTML表單助手正確,但看着真棒這樣的:

<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> 

你也可以看到,其用在Spark code base here代碼示例項目。

希望對您有所幫助
Rob

相關問題