2011-12-19 37 views
8

Tôi đang cố gắng tạo hộp thoại bật lên để cho phép người dùng điền vào biểu mẫu. Khi họ nhấp gửi, tôi muốn gửi biểu mẫu. Tôi đã tìm ra cách làm cho cửa sổ bật lên phương thức nhưng không thể tìm ra cách để làm cho nó gửi biểu mẫu khi biểu mẫu được nhấp. Có ai biết cách để làm điều này không?ASP.Net MVC 3 Biểu mẫu Hộp thoại Giao diện Người dùng Jquery

@using (Html.BeginForm()) 
{ 
    <div> 
     <fieldset> 
      <legend>Account Information</legend> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.UserName) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.UserName) 
       @Html.ValidationMessageFor(m => m.UserName) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.Password) 
      </div> 
      <div class="editor-field"> 
       @Html.PasswordFor(m => m.Password) 
       @Html.ValidationMessageFor(m => m.Password) 
      </div> 

      <div class="editor-label"> 
       @Html.CheckBoxFor(m => m.RememberMe) 
       @Html.LabelFor(m => m.RememberMe) 
      </div> 

      <p> 
       <input type="submit" value="Log On" /> 
      </p> 
     </fieldset> 
    </div> 
} 

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#dialog-form").dialog({ 
      modal: true, 
      buttons: { 
       "Submit": function() { 
        $(this).dialog("close"); 
       }, 
       Cancel: function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
    }); 
</script> 

Trả lời

8

Bạn cần đảm bảo bạn có phương thức POST hợp lệ trong trình điều khiển của mình để gửi biểu mẫu. Biểu mẫu của bạn ở đây có vẻ hợp lệ miễn là bạn không mong đợi nút gửi của hộp thoại để gửi biểu mẫu. Nếu đó là trường hợp thì bạn sẽ cần phải cung cấp cho các hình thức một ID và gọi trình từ chức năng của bạn cho hộp thoại "Gửi" nút.

<div id="dialog-form"> 
@using (Html.BeginForm("LogOn", "Account", FormMethod.Post, new { id = "LogOnForm" })) { 
    <div> 
     <fieldset> 
      <legend>Account Information</legend> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.UserName) 
      </div> 
      <div class="editor-field"> 
       @Html.TextBoxFor(m => m.UserName) 
       @Html.ValidationMessageFor(m => m.UserName) 
      </div> 

      <div class="editor-label"> 
       @Html.LabelFor(m => m.Password) 
      </div> 
      <div class="editor-field"> 
       @Html.PasswordFor(m => m.Password) 
       @Html.ValidationMessageFor(m => m.Password) 
      </div> 

      <div class="editor-label"> 
       @Html.CheckBoxFor(m => m.RememberMe) 
       @Html.LabelFor(m => m.RememberMe) 
      </div> 

      <p> 
       <input type="submit" value="Log On" style="display:none;" /> 
      </p> 
     </fieldset> 
    </div> 
} 
</div> 
<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#dialog-form").dialog({ 
      modal: true, 
      buttons: { 
       "Submit": function() { 
        $("#LogOnForm").submit(); 
       }, 
       Cancel: function() { 
        $(this).dialog("close"); 
       } 
      } 
     }); 
    }); 
</script> 
+0

Awesome yeah đã hoạt động. Tôi nghĩ rằng những gì tôi không hiểu là bạn có thể cung cấp cho người trợ giúp Html tạo ra một ID. Tôi cho rằng sử dụng phương pháp đó bạn chỉ có thể đổ bất cứ điều gì bạn muốn vào thẻ html thats đang được tạo ra? –

+0

Miễn là nó là thuộc tính HTML hợp lệ, bạn nên ổn. – ptfaulkner

Các vấn đề liên quan