开发者

Jquery readonly text box invisible on post to MVC controller

If the user clicks the use above address the value is set in Address1 and is disabled. The value is not passed in the form submit but I can get it from the model.Address in the Controller. If ModelState.IsValid is not valid I get the field model.Address1 back empty how can I populate it with model.Address?

View
$("#MailAddressAsAbove").click(function () {
开发者_JAVA百科   if ($(this).attr("checked") == true) {
      $('#Address1').attr("disabled", true);
   }
}

Controller

[HttpPost]
public ActionResult Enquiry(PersonViewModel model)
{
   if (model.MailAddressAsAbove)
   {
      model.Address1 = model.Address;
   }

   if (!ModelState.IsValid)
   {
      return Enquiry();
   }

}

Thanks


Feel free to correct me if I cannot get what you want to ask.

Firstly, all disabled form elements will not be included in the form submit. But readonly element will be included.

So may be you can try to use readonly instead of disabed attribute?

$("#MailAddressAsAbove").click(function () {
   if ($(this).attr("checked") == true) {
      $('#Address1').attr("readonly", "readonly");
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜