开发者

ASP.NET MVC: Simply can't seem to get any output. help!

开发者 https://www.devze.com 2023-03-22 15:26 出处:网络
In Visual Web Developer when I \"run\" my Controller (TestApp) I come up with this: http://postimage.org/image/iggcs6hw/

In Visual Web Developer when I "run" my Controller (TestApp) I come up with this:

http://postimage.org/image/iggcs6hw/

I've tried adding "/TestApp" on the end of the local host address in the address bar and t开发者_StackOverflowhat gave me this result:

http://postimage.org/image/ih078cf8/

I don't think I've misspelled anything. Forgive me if this question is a stupid one, just trying to get my feet off the ground :D.


Make sure you have renamed the default ~/Views/Home folder that was generated when you created your project into ~/Views/TestApp folder. As far as the first error message is concerned make sure you have modified the default routes in Global.asax to make the TestApp controller the default one instead of Home:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "TestApp", action = "Index", id = UrlParameter.Optional }
);

So to sum up:

  • Make sure that you have an Index.aspx view inside the ~/Views/TestApp folder.
  • Make sure that you have set the TestApp controller in the default route in Global.asax
  • Make sure that your TestApp controller has an Index action

Now you will be able to call your application like this: http://example.com/ which will automatically call the Index action on TestApp controller which will render the ~/Views/TestApp/Index.aspx view.


Make sure your views are in the /Views directory. MVC follows a strict folder structure and this happens when it can't find something.

When adding a new view or controller to an MVC project, it's best to use the wizard provided for that purpose.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号