我需要GET和POST澄清一些关于JQuery的AJAX和MVC 3 [英] I need some clarification on GET and POST concerning JQuery AJAX and MVC 3
本文介绍了我需要GET和POST澄清一些关于JQuery的AJAX和MVC 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道,如果它是一个全有或全无的情况。我想这样做,通过负载正常MVC 3(GET)我的网页控制器采用型号并通过它来查看。查看和剃刀渲染。然而,当我回来后,我想这回发通过AJAX选定的信息。这可能吗?还是我做GET和POST使用AJAX?
I am wondering if it is an all-or-nothing situation. What I would like to do, Load (GET) my page by normal MVC 3. Controller takes Model and passes it to View. View and Razor render it. However, when I post back, I'd like it to postback the selected info through AJAX. Is this possible? Or do I have do GET and POST with AJAX?
推荐答案
尝试类似下面的。结果
控制器code:
Try something like the below.
Controller Code:
[HttpGet]
public ActionResult WhateverActionName()
{
YourViewModel yvm = new YourViewModel();
//Initalize viewmodel here
Return view(yvm);
}
[HttpPost]
public ActionResult WhateverActionName(YourViewModel yvm)
{
if (ModelState.IsValid) {
RedirectToAction("OtherAction", "OtherController")
}
return View(yvm);
}
阿贾克斯:
$.ajax({
url: myurl
// processData: false, // you may need this option depending on service setup
success: function(){
location.href = "TARGET LOCATION";
},
type: "POST"
});
有关目标定位:你将需要养活AJAX包含的任何URL下生成一个变量
For target location: You're going to need to feed the ajax a variable containing whatever URL the following generates
@URL.Action("Action", "Controller")
这篇关于我需要GET和POST澄清一些关于JQuery的AJAX和MVC 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文