[英]How to pass Model to a Controller from a confirm Dialog written with JavaScript
I have a HTML page which has a model as follows: 我有一个具有以下模型的HTML页面:
@model ViewModel.Ekranlar.ModelVM
I call a Confirm Dialog written with JavaScript in the html page as in the following: 我在html页面中调用用JavaScript编写的“确认对话框”,如下所示:
<script type="text/javascript">
$(document).ready(function () {
$(".confirmDialog").on("click", function (e) {
// e.preventDefault(); use this or return false
var url = $(this).attr('href');
$("#dialog-confirm").dialog({
autoOpen: false,
resizable: false,
height: 170,
width: 350,
show: { effect: 'drop', direction: "up" },
modal: true,
draggable: true,
buttons: {
"OK": function () {
$(this).dialog("close");
window.location = url;
}, "Cancel": function () {
$(this).dialog("close");
}
}
});
$("#dialog-confirm").dialog('open');
return false;
});
}); </script>
And the controller is as in the following: 控制器如下所示:
public ActionResult DUDBaskaniBuro2GidenIptal(ModelVM model)
How can I pass ModelVM
model to the Action in the controller? 如何将
ModelVM
模型传递给控制器中的Action?
Thanks for your helps. 感谢您的帮助。
Though not sure if you are using jquery modal or your custom one, but: 尽管不确定是否使用jquery模式或自定义模式,但是:
1) If you want to do full page postback, you may make the 'OK' button a 'submit' button type so that on click it will postback to the url mentioned in the form tag. 1)如果要进行全页回发,可以将“确定”按钮设为“提交”按钮类型,以便在单击时将其回发到form标记中提到的url。
<input type="submit" value="OK" .../>
2) If you want to do partial postback, you may use something like: 2)如果要进行部分回发,则可以使用以下方法:
"OK": function () {
$.post('@Url.Action("ActionMethod","ControllerName")',
<captured values via jquery/javascript as json>, //E.g. {"Id":1,"Name":"My Name"}
function(data){
//Code you want to do here
$(this).dialog("close"); //Just an example
window.location = data.url; //Just an example
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.