使用 jquery 对话框按钮在 asp.net 中触发 actionresult 方法
有没有办法让 jQuery 对话框按钮触发控制器中的方法,使其像提交按钮一样工作?
控制器中的代码
[HttpPost]
public ActionResult Create(Film filmToCreate){
try{
filmToCreate = new Film();
System.Diagnostics.Debug.WriteLine("Constructed Film");
UpdateModel(filmToCreate);
System.Diagnostics.Debug.WriteLine("Updated Model");
repo.Add(filmToCreate);
System.Diagnostics.Debug.WriteLine("Added Film");
repo.Save();
System.Diagnostics.Debug.WriteLine("Save Databases");
System.Diagnostics.Debug.WriteLine("Return1");
return RedirectToAction("Index");
}
catch {
System.Diagnostics.Debug.WriteLine("Caught something");
return RedirectToAction("Create");
}
}
// 对话框中的代码
buttons: {
"Create": function() {
},
"Reset": function() {
$("#createForm input").attr("value", "");
},
"Close": function() {
$(this).dialog('close');
}
}
Url
类中是否有某种方法能够将此方法链接到此按钮?
Is there a way of making a jQuery dialog button trigger a method in controller so it works like a submit button?
Code in controller
[HttpPost]
public ActionResult Create(Film filmToCreate){
try{
filmToCreate = new Film();
System.Diagnostics.Debug.WriteLine("Constructed Film");
UpdateModel(filmToCreate);
System.Diagnostics.Debug.WriteLine("Updated Model");
repo.Add(filmToCreate);
System.Diagnostics.Debug.WriteLine("Added Film");
repo.Save();
System.Diagnostics.Debug.WriteLine("Save Databases");
System.Diagnostics.Debug.WriteLine("Return1");
return RedirectToAction("Index");
}
catch {
System.Diagnostics.Debug.WriteLine("Caught something");
return RedirectToAction("Create");
}
}
// Code in dialog
buttons: {
"Create": function() {
},
"Reset": function() {
$("#createForm input").attr("value", "");
},
"Close": function() {
$(this).dialog('close');
}
}
Is there some method in the Url
class that will be able to link this method to this button?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据 API 你会做这样的事情:
According to the API you would do something like this: