【问题标题】:Jquery readonly text box invisible on post to MVC controllerJquery只读文本框在发布到MVC控制器时不可见
【发布时间】:2011-12-07 10:15:28
【问题描述】:

如果用户单击使用上述地址,则该值在 Address1 中设置并被禁用。 该值未在表单提交中传递,但我可以从 Controller 中的 model.Address 获取它。如果 ModelState.IsValid 无效,我将字段 model.Address1 返回为空,如何使用 model.Address 填充它?

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

控制器

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

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

}

谢谢

【问题讨论】:

    标签: jquery asp.net-mvc model-view-controller asp.net-mvc-2


    【解决方案1】:

    如果我无法得到您想问的问题,请随时纠正我。

    首先,所有禁用的表单元素都不会包含在表单提交中。 但会包含 readonly 元素。

    那么您是否可以尝试使用 readonly 而不是 disabed 属性?

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-12-15
      • 1970-01-01
      • 2021-08-08
      • 2013-01-20
      • 1970-01-01
      • 2017-12-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多