razor - Html.BeginForm not outputting Form for first item in collection -
i using mvc5 , want display form each item in collection. form post action in different controller when submitted.
my razor follows:
@foreach (var skuinorder in model.order.skus) { using (html.beginform("delete", "skuinorders", new { id = skuinorder.id }, formmethod.post, new { name = skuinorder.id, id = skuinorder.id })) { <input id="orderid" name="orderid" value="model.order.id" type="hidden" /> <input type="submit" class="btn btn-default" value="delete" /> } }
this code works items in collection apart first one.
for second item onwards, form element displayed , works expected, form not outputted first item. instead 2 elements not within element.
this example of outputted html (with 2 items in collection) via firefox dev tools. notice there no form first item , inputs displayed on own, there form second item.
i cannot post images not have enough rep can download form here: https://onedrive.live.com/redir?resid=999be3b43db18398%211133026
update have discovered behaviour standard html form (not @html.beginform). example, razor code removes form elements first item not subsequent ones.
<form action="/skuinorders/delete/@skuinorder.id" method="post" > <input id="orderid" name="orderid" value="@model.order.id" type="hidden" /> <input type="submit" class="btn btn-default" value="delete" /> </form>
this resolved ... because had nested forms (the whole page edit page wrapped in form).
this question explains it: form tag dissapear in foreach loop razor mvc 3
Comments
Post a Comment