Reputation: 96
So I have a partial view inside which I am creating a form
@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>
}
But the HTML being rendered has the form closing immediately, followed by the html inside the curly braces. For example:
<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>
and so on. This partial view is being inserted into a table row ()
Any ideas why this is happening and how I can fix it?
Upvotes: 2
Views: 2246
Reputation: 8020
It might have something to do with you trying to put a form over a td tag, which basically puts the form right in the tr; which is not correct. You should try to put the form inside the td instead of outside.
Upvotes: 3
Reputation: 11
You shouldn't need to include an '@' in the BeginForm parameters.
@using(Html.BeginForm("UpdateTimesheet", "Entry", FormMethod.Post, new { id = i }))
will work fine.
Upvotes: 1