Jquery readonly文本框在post - MVC控制器上是不可见的

[英]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?

如果用户单击上面的使用地址,该值将在Address1中设置并禁用。这个值不会在表单submit中传递,但是我可以从模型中获得它。地址在控制器。如果状态。我得到的是场模型。如何用model.Address填充它?

View
$("#MailAddressAsAbove").click(function () {
   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

谢谢

1 个解决方案

#1


2  

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.

首先,所有禁用的表单元素将不包含在表单提交中。但是readonly元素将包括在内。

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

所以你可以尝试使用readonly而不是disabed属性吗?

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

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/10/14/35af99a5e886eba2c99f05e941d449d1.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号