ASP.Net MVC jQuery的对话部分 [英] ASP.Net MVC jQuery Dialog Partial
本文介绍了ASP.Net MVC jQuery的对话部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
也许有人在那里可以帮助我了解发生了什么事情。我使用jQuery UI对话框()在我的项目显示HTML谐音。当用户点击添加新它显示添加客户端窗体。但是,当用户点击添加或对话框我得到一个错误的取消按钮,$(本).dialog不是一个函数。如果我删除了open事件,在对话框中显示静态形式的按钮做工精细。
Perhaps someone out there can help me understand what's going on. I'm using jQuery UI dialog() to display html partials in my project. When a user clicks Add New it displays the add client form. However, when the user clicks on the Add or Cancel buttons in the dialog I get an error, "$(this).dialog is not a function". If I remove the open event and display a static form in the dialog the buttons the work fine.
ClientsController
ClientsController
public ActionResult ajaxCreateClient()
{
Client c = new Client();
AddToViewData(c); // adds some additional info about client
return PartialView("__ClientForm", c);
}
查看:联系人/创建
....
<p>
@Html.LabelForField(model => model.Client.Name) <!-- custom extension that I wrote -->
@Html.TextboxFor(model => model.Client.Name)
<a id="btnAddNew" href="javascript:void()">Add New</a>
</p>
....
<div id="addNew"></div>
jQuery的
jQuery
$(document).ready(function () {
$("#btnAddNew").click(function () {
$("#addNew").dialog("open");
});
$("#addNew").dialog({
autoOpen: false,
title: "Add Client",
width: 410,
modal: true,
resizable: false,
open: function(event, ui) {
$(this).load("@Url.Action("ajaxCreateClient", "Clients")");
},
buttons:
{
"Add": function () {
// validate() and do something
$(this).dialog("close");
},
"Cancel": function () {
// do something else
$(this).dialog("close");
}
}
});
});
谢谢!
推荐答案
尝试这样的:
$('#addNew').dialog('close');
这篇关于ASP.Net MVC jQuery的对话部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文