【发布时间】:2013-12-20 21:20:04
【问题描述】:
我一直在关注如何使用 ajax 在现有网页中加载部分视图的书中的示例,但无法使其正常工作。
Chrome 的元素检查器告诉我找不到文件 (404),但是当我手动导航到页面时,它加载正常。
这是我的控制器:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcApplication1.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
ViewBag.Message = "Hello";
return View();
}
[HttpGet]
public PartialViewResult HelloWorld()
{
ViewBag.Message = "Hello World";
return PartialView();
}
}
}
这是我的主要观点:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<title>index></title>
<script src="../../Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
</head>
<body>
<div>
<div id="divMessage">@ViewBag.Message</div>
@Ajax.ActionLink("Refresh", "HelloWorld", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "divMessage", InsertionMode = InsertionMode.Replace })
</div>
</body>
</html>
这是我的部分观点:
@ViewBag.Message
任何人都可以提出任何为什么这不起作用的原因吗?
谢谢
【问题讨论】:
标签: ajax asp.net-mvc model-view-controller razor