0

Using MVC3 and Ajax.BeginForm I surprisingly discovered that mvc ajax forms submits elements with the attribute disabled="disabled".

I have tested both select and text inputs.

I was suprised because they should not be submited and they will not when using Html.BeginForm.

Is there some hidden option or a workaround for this?

[EDIT example]

 @using (Ajax.BeginForm("Action", "Control", new AjaxOptions() { HttpMethod = "POST" }))
{

  <input type="text" name="_enabled" value="_enabled" />
  <input type="text" name="_disabled" value="_disabled" disabled="disabled" />

  <input type="submit" value="POST" />

}

Posted data

Html.BeginForm will not post the _disabled value.

4

1 回答 1

0

您可以在其他隐藏元素中设置禁用元素值:

<input type="text" name="Id" id="Id" value="5" />

<input type="hidden" name="Id" id="Id" value="5" />

和或:

@Html.TextBoxFor(m => m.Id)
@Html.HiddenFor(m => m.Id)
于 2016-03-08T10:06:05.907 回答