码迷,mamicode.com
首页 > Web开发 > 详细

UrlHelperDemo,AjaxHelperDemo

时间:2015-08-31 23:18:56      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

@{
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());
}

}

UrlHelperDemo,AjaxHelperDemo

标签:

原文地址:http://www.cnblogs.com/anling-yao/p/4774358.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!