1. MVC 路由
  2. 重定向
  3. 问题记录
1)MVC 路由
入口方法:
(Global.asax)Application_Start()--->(App_Start/RouteConfig.cs)RegisterRoutes()--->(Controllers/)Controller--->(Views/)Action--->(Views/Action/)View
其中Application_Start()代码如下:
<span style="font-size:14px;font-weight: normal;"><span style="font-size:14px;">namespace MvcAspxMovie
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute(
name: "Default",//路由名称
url: "{controller}/{action}/{id}",//带有参数的URL
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }//默认参数
);
}
}
}</span></span>

2)重定向:页面跳转传参(RedirectToAction())

在MVC中页面后台中常用的页面跳转方法有几种,如:return View()、return RedirectToAction().
  一般情况下我们返回的都是本页面,所以使用return View()就够了.有时候我们也会遇到返回的页面不是本页面的,就要用到return
RedirectToAction();方法了。
举例如下,通过RedirectToAction调用跳转到HelloWorld(),页面返回“helloworld”。
        public string HelloWorld()
{
return "hello world";
}
public ActionResult TestRedirect()
{
return RedirectToAction("HelloWorld");
}
遇到需要传参的情况,则需要对RedirectToAciton()扩展
RedirectToAction(string ActionName);  //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到同一Controller 里面的不同Action</span>
RedirectToAction(string ActionName, object viewData); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到同一Controller 里面的不同Action,含参数</span>
RedirectToAction(string ActionName, string ControllerName); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到不同Controller 里面的不同Action</span>
RedirectToAction(string ActionName, string ControllerName, object viewData); //<span style="font-family: Arial; font-size: 14px; line-height: 26px;">跳转到不同Controller 里面的不同Action,含参数</span>
<span style="font-family: Arial; font-size: 14px; line-height: 26px;"><span style="font-family: Arial; font-size: 14px; line-height: 26px;">如:RedirectToAction("Index","Home",new {msg="操作成功",name="admin"});</span>
</span>
<%: Html.ActionLink("Edit", "Edit", new { id=item.ID }) %> 

举例如下,调用TestRedirect()最终页面返回“hello bailang”

        public string HelloWorld(string str)
{
return "hello "+str;
}
public ActionResult TestRedirect()
{
return RedirectToAction("HelloWorld",new{str="bailang"});
}

3)问题记录

20160104 初学MVC 遇到新建一个controller,默认action
是index,URL输入 http://localhost:15683/TestThumbnail 默认为http://localhost:15683/TestThumbnail/index,但未知修改会造成再次URL输入默认到index不起作用,必须定位输入http://localhost:15683/TestThumbnail/index,原因发现为:在根目录下生成同名controller的目录。
解决方法:删除该目录即可。

最新文章

  1. Quartz 在 Spring 中如何动态配置时间--转
  2. Js位置与大小(1)&mdash;&mdash;正确理解和运用与尺寸大小相关的DOM属性
  3. C#复习⑧
  4. DropZone
  5. MVC学习笔记---MVC框架执行顺序
  6. jQuery 写的幻灯左右切换插件
  7. javascript 判断浏览器的ie版本,替换html标签
  8. 利用DetachedCriteria实现模糊查询和分页
  9. bzoj2741【FOTILE模拟赛】L
  10. 不包含任何UserControl
  11. 在FL2440上使用kei MDK 调试程序(J-link)
  12. 2018/1/15 JAVA多线程相关
  13. Hall定理 二分图完美匹配
  14. win10下安装Cygwin配置gcc编译环境
  15. 第二周博客作业 &lt;西北师范大学| 周安伟&gt;
  16. 认识EasyUI——DataGrid的onClickRow事件
  17. 主流前端框架对比:Vue.js , React, Angular.js
  18. Power BI 与 Azure Analysis Services 的数据关联:4、Power BI 连接到Azure Analysis Services 并展示
  19. lxml基础
  20. 20170719xlVbaAbsorbProcedure

热门文章

  1. git命令?
  2. ECMAScrip5 二
  3. IsDate(expression)函数
  4. Explain 参数详解,重点部分已经全部完成,还有少数几个参数没不理解没标注。
  5. GUI学习之二十五——QFontDialog学习总结
  6. GUI学习之十五——QAbstractSpinBox学习总结
  7. MyEclipse XML &amp; XML架构教程:XML Schema (XSD)编辑器
  8. NOIP2016 D2T2 蚯蚓
  9. 【leetcode】1129. Shortest Path with Alternating Colors
  10. git初步研究2