是否可以做
1) $('#form').submit();
但这样
2) $.post('/controller/function',formData,function(result){
// I want here to do the same as $('#form').submit();
});
解释当我在返回时执行 1) 时,它将使用与我在服务器端返回的 View 相关的模型填充我的所有输入
return View(model);
此外,如果我通过在服务器端指定 View 来返回不相关的 View 和模型,它将加载带有模型的 View 。
return View(view,model);
我喜欢这种行为,但它的缺点是,它总是会在服务器端调用相同的函数
我想要的是,我希望能够在服务器端调用不同的函数,并保持与调用 1) 时发生的行为相同的行为
通过2)我可以调用我想要的函数,但我不知道如何使返回行为与1)相同(自动填充我的输入或返回重定向加载模型的良好 View (用模型填充输入数据))
服务器端(如果有帮助的话)
//Use when I perform some search on my page or few actions
//Called with 1)
[HttpPost]
public ActionResult defaultFunction(Model model)
{
//Doing some code
return View(model);
}
//Use on button click I want to switch page to perform some action
//Return the view with the model all ready for the action to be
//perform by the user
//Called with 2) but not doing what I want
// If I move the code in the defaultFunction and called it with 1) it do
//what I want : redirect the browser to the view with the model ...
[HttpPost]
public ActionResult redirectFuntion(Model model)
{
//Doing some code
return View("View",model);
}
谢谢 抱歉,英语不是我的母语。
最佳答案
感谢@kblok
根据他的评论,我为我的解决方案这样做了:
$('#form').attr('action','/controller/function').submit();
// it doing the same as if i did $('form').submit(); but I can specified the
// called function on the server side.
它有效!
关于javascript - $ ('#Form' ).submit 与 $.post,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47415488/