asp.net - Need help with Razor syntax in cart index view (Razor view engine) -



asp.net - Need help with Razor syntax in cart index view (Razor view engine) -

at first utilize loved , felt much less cluttered webforms <%: %> etc. view engine, upon using farther can't help notice it's hypersensitive "{" parentheses placed , other scenarios. gives errors @ points older view engine not picky.

for illustration below code produce error because form helper closing bracket } under </table> tag. if place higher above </tbody> works! don't need there because submit button input has nested within , don't want set button input table.

@model carttest.models.cart @{ viewbag.title = "index"; } <h2>cart index</h2> <table width="80%" align="center"> <thead> <tr> <th align="center">quantity</th> <th align="left">item</th> <th align="right">price</th> <th align="right">subtotal</th> </tr> </thead> <tbody> @{int index = 0;} @using (html.beginform("updatecart","cart")) { foreach (var line in model.lines) { <tr> @html.hidden("lines.index", index) <td align="center">@html.textbox("lines[" + index + "].quantity", line.quantity)</td> <td align="left">@line.product.name</td> <td align="right">@line.product.price</td> <td align="right">@(line.quantity * line.product.price)</td> <td align="right">@html.actionlink("remove", "removeitem", new { productid = line.product.productid }, null)</td> </tr> index++; } </tbody> <tfoot></tfoot> </table> <input type="submit" value="update cart" /> }

the reason works above </tbody> because declared beginform within opening <tbody>. must nested in order work. if don't want set input button within table, move beginform outside table element opening , closing brace @ same level.

@using (html.beginform("updatecart","cart")) { <table width="80%" align="center"> <thead><tr> <th align="center">quantity</th> <th align="left">item</th> <th align="right">price</th> <th align="right">subtotal</th> </tr></thead> <tbody> @{int index = 0;} foreach (var line in model.lines) { <tr> @html.hidden("lines.index", index) <td align="center">@html.textbox("lines[" + index + "].quantity", line.quantity)</td> <td align="left">@line.product.name</td> <td align="right">@line.product.price</td> <td align="right">@(line.quantity * line.product.price)</td> <td align="right">@html.actionlink("remove", "removeitem", new { productid = line.product.productid }, null)</td> </tr> index++; } </tbody> <tfoot> </tfoot> </table> <input type="submit" value="update cart" /> }

asp.net asp.net-mvc asp.net-mvc-3 razor

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -