我试图从模态弹出窗口发布对象的反馈.服务器端没有填充弹出窗口中的值. div class="modal fade" id="msg-editor" div class="modal-header" a class="close" data-dismiss="modal"times;/a h3Title of the form/h3 /div div
<div class="modal fade" id="msg-editor"> <div class="modal-header"> <a class="close" data-dismiss="modal">×</a> <h3>Title of the form</h3> </div> <div class="modal-body"> <div class="row-fluid"> <div class="controls span10"> <label class="control-label" for="Title">Title and message</label> <input type="text" class="input-xlarge" id="Title" name="Title" placeholder="Title of the message" /> <textarea class="input-xlarge" id="Message" name="Message" rows="5" cols="9" placeholder="Message"></textarea> <label class="checkbox"> <input type="checkbox" value="option2" id="EmailSelf"> Send a copy of this message to yourself </label> </div> </div> </div> <div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Close</a> <a id="Submit" class="btn btn-primary" href="@Url.Action("AddDocumentMessage", "Invoice", new { param1 = $('#myFormSubmit').value, param2 = Model.Obj.Value1, param3 = Model.HashedValue })">Send</a> </div> </div>
不起作用的部分是
param1 = $(‘#myFormSubmit’).value.
如何传递客户端值?
你不能……!因为剃刀代码在服务器端和服务器中被解析和呈现,所以没有jquery或任何客户端代码或数据……
另一种类似的工作可能如下:
<div class="modal-footer"> <a href="#" class="btn" data-dismiss="modal">Close</a> <input type="button" value="Send" onclick="submit()" /> </div> <script> function submit() { $.ajax({ url: @Url.Action("act", "con") + '?param1=' + $('#myFormSubmit').value + '¶m2=' @Model.Obj.Value1 + '¶m3=' + @Model.HashedValue, type: 'POST', // ... other ajax options ... }); } </script>
然后,在您的操作方法中,您将收到字符串中的所有参数:
[HttpPost] public ActionResult act(string param1, string param2, string param3) { ViewBag.Message = "Your contact page."; return View(); }