asp.net – MVC4 – ContextDependentView – 这是什么意思?
发布时间:2021-03-30 23:46:02 所属栏目:asp.Net 来源:互联网
导读:我刚刚开始使用MVC4,我看到的第一个动作方法有新的东西.我检查了互联网,找不到任何关于这个: public ActionResult LogOn() { return ContextDependentView(); } 有谁知道ContextDependentView是什么? 对我来说新鲜事 这是为了方便查看或PartialView操作结果
我刚刚开始使用MVC4,我看到的第一个动作方法有新的东西.我检查了互联网,找不到任何关于这个: public ActionResult LogOn() { return ContextDependentView(); } 有谁知道ContextDependentView是什么? 对我来说新鲜事 解决方法这是为了方便查看或PartialView操作结果的登录和注册操作.private ActionResult ContextDependentView() { string actionName = ControllerContext.RouteData.GetRequiredString("action"); if (Request.QueryString["content"] != null) { ViewBag.FormAction = "Json" + actionName; return PartialView(); } else { ViewBag.FormAction = actionName; return View(); } } 像MVC中的其他东西一样,它是通过惯例完成的…这里的约定是当Request.QueryString包含一个?content = xxxx时,它为操作名称添加“Json”,并将其添加到ViewBag属性中,并返回部分版本风景.例如: 请求/ Account / Login?content = test将被解析为ViewBag.FormAction =“JsonLogin”;然后返回一个部分. 对/ Account / Login的请求没有内容查询字符串,因此其表单操作仍然是ViewBag.FormAction =“Login”; (编辑:莱芜站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
推荐文章
站长推荐
热点阅读