我想使用Ajax脚本调用视图:
在主视图中:
// GET: Bob/Details/5
public ActionResult Details(String ID)
{
int id = Convert.ToInt32(ID);
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
BobRepository bobRepository = new BobRepository();
Bob bob = bobRepository.GetBob(id);
if (bob == null)
{
return HttpNotFound();
}
return View(bob);
}
控制器:
{{1}}
调用控制器的函数调用,不返回turget视图。是什么原因?
答案 0 :(得分:0)
我不确定你要做什么,我假设你在一些弹出模式中填充该视图,首先你需要返回部分视图而不是视图,我建议检查请求然后返回部分视图,否则返回视图, 像这样的东西
if(Request.IsAjaxRequest())
{return PartialView(bob);}
else
return View(bob);
在你的js中,将文本解析为html,你可以使用is ajax
success: function (response) {
var result = $.parseHTML(response);
//do what you want with your html