在MVC中路由PARAMETRS [英] Routing PARAMETRS in MVC

查看:88
本文介绍了在MVC中路由PARAMETRS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我是MVC网站开发的新手,所以我试图发现这种模式。

我试图创建一个在页面之间导航的新MVC应用程序。所以我创建了3个视图(主页,产品,关于)和控制器(站点)示例来自上一个实验室在7天 - 第2天逐步学习MVC(模型视图控制器) [ ^ ]



控制器代码:



Hello
I am new to MVC web development so I am trying to discover this pattern.
I tried to create a new MVC application that navigate between pages.So I create 3 views (home,product,about) and a controller (Site)"The example is taken from the last lab Learn MVC (Model view controller) Step by Step in 7 days – Day 2[^]

code of the controller:

public class SiteController : Controller
   {
       //
       // GET: /Site/

       public ActionResult GoTohome()
       {
           return View("Home");
       }
       public ActionResult AboutUs()
       {
           return View("About");
       }
       public ActionResult SeeProduct()
       {
           return View("Product");
       }





我确信我没有得到路由人员,因为在调试时我会得到未找到主页或其主人的视图。搜索了以下位置

我修改了这样的global.asax文件





I am sure that i didn''t get the routing staff because when debugging I get "The view ''Home'' or its master was not found. The following locations were searched"
I have modified the global.asax file like this

public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                 "Default", // Route name
                 "{controller}/{action}/{id}", // URL with parameters
                 new { controller = "Site", action = "GoTohome", id = UrlParameter.Optional } // Parameter defaults
             );







感谢您的帮助。




Thank you for your help.

推荐答案

new { controller = "Site(controler name) ", action = "GoTohome(action name)", id = UrlParameter.Optional }



查看此部分....



如果在家查看,则行动名称必须在家...




check this part ....

if home is view than action name must be home..

new { controller = "Site ", action = "home", id = UrlParameter.Optional }


我发现错误,我必须在Views文件夹中添加一个名为Site的文件夹。但是我没有'不知道我应该添加这个文件夹,因为Site是控制器的名称而不是文件夹



任何解释
I found the error,I have to add a folder named Site into the Views folder.However i didn''t get why i should add this folder because Site is the name of the controller not the folder

any explanation


这篇关于在MVC中路由PARAMETRS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆