可以做
1) $('#form').submit();
但是,这种方式
2) $.post('/controller/function',formData,function(result){
// I want here to do the same as $('#form').submit();
});
说明当我做1)返回时,它将填充我的所有输入,并使用与我在服务器端返回的视图相关的模型
return View(model);
另外,如果我通过在服务器端指定视图来返回不相关的视图和模型,它将使用模型加载视图。
return View(view,model);
我喜欢这种行为,但是它的不良方面,它将始终在服务器端调用相同的功能
我想要的是我希望能够在服务器端调用不同的功能,并保持与我呼叫1时发生的行为相同的行为)
使用2)我可以调用我想要的功能,但我不知道如何使返回与1相同)(自动填充我的输入或返回使用已加载的模型的好视图(用模型填写的输入)数据))
服务器端(如果可以帮助)
//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.
它起作用!