所以我有一个局部视图,我在其中创建一个表单
@using(Html.BeginForm("UpdateTimesheet", "Entry", FormMethod.Post, new { id = @i }))
{
<td>@Html.DropDownListFor(x => x.TimeEntry.LocationId, Model.LocationList, "Please select a location")</td>
<td>@Html.DropDownListFor(x => x.TimeEntry.Equipment.Code, Model.EquipmentList, "Please select equipment")</td>
<td>@Html.DropDownListFor(x => x.TimeEntry.Staff.PayrollId, Model.StaffList, "Please select staff")</td>
<td>@Html.DropDownListFor(x => x.TimeEntry.Task.Name, Model.TaskList, "Please select a task")</td>
<td>@Html.EditorFor(x => x.TimeEntry.LengthOfTime)</td>
<td>@Html.DisplayFor(x => x.TimeEntry.EventDateTime)</td>
<td>@Html.DisplayFor(x => x.TimeEntry.ReceivedDateTime)</td>
<td>
@Html.ActionLink("Cancel", "DisplayTimesheet", new { id = Model.TimeEntry.Id }, new { @class = "edit" })
|
<a style="cursor: pointer" onclick="submitEdit(@i);">Save</a>
</td>
}
但是呈现的HTML会立即关闭表单,然后是花括号内的html。例如:
<form action="/Entry/UpdateTimesheet" id="edit1" method="post"></form>
<td>
<select data-val="true" data-val-number="The field LocationId must be a number." id="TimeEntry_LocationId" name="TimeEntry.LocationId">
<option value="">Please select a location</option>
<option value="1">Location 1</option>
<option selected="selected" value="3">Location 1</option>
</select>
</td>
等等。此部分视图正在插入表格行()
为什么会发生这种情况以及如何解决这个问题?
答案 0 :(得分:3)
这可能与您尝试将表单放在td标记上有关,这基本上将表单放在tr中;这是不正确的。您应该尝试将表单放在td而不是外部。
答案 1 :(得分:1)
您不需要在BeginForm参数中包含“@”。
@using(Html.BeginForm("UpdateTimesheet", "Entry", FormMethod.Post, new { id = i }))
可以正常使用。