@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div>
//1.0 根据路由规则生成url
<a href="@Url.Action("Index", "Home", new { id = 100 })">跳转到首页</a>
<br />
@Url.Encode("http://www.baidu.com?name=八戒")
<br />
@{
var str = "http%3a%2f%2fwww.baidu.com%3fname%3d%e5%85%ab%e6%88%92";
var res = Server.UrlDecode(str);
@res;
}
<br />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.js")"></script>
<br />
@Url.HttpRouteUrl("Default", new { conroller = "Home", action = "index", id = 100 })
<br />
//2.0 RouteData存储了 控制器名称,方法名称,和参数值
<br />
@Url.RequestContext.RouteData.Values["controller"]<br />
@Url.RequestContext.RouteData.Values["action"]<br />
</div>
</body>
</html>
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
</head>
<body>
<div>
@Ajax.ActionLink("获取服务器时间", "GetTime", "C03AjaxHelperDemo", new AjaxOptions()
{
HttpMethod = "post", //为了防止ajax将第一次的结果缓存,请使用post
UpdateTargetId = "resDiv"
})
</div>
<div id="resDiv" style="height: 50px; border: 1px solid red;"></div>
</body>
</html>
Controller
public class C03AjaxHelperDemoController : Controller
{
//
// GET: /C03AjaxHelperDemo/
public ActionResult Index()
{
return View();
}
public ActionResult GetTime()
{
return Content(DateTime.Now.ToString());
}
}