如何在MVC应用程序中打印Hello world? [英] How to print Hello world in MVC application ?

查看:130
本文介绍了如何在MVC应用程序中打印Hello world?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

快速转到控制器文件夹然后 - >右键单击 - >添加 - > gt;控制器 - >确定。然后来到controller.cs页面

和那段代码视图是: -



Fast go to controllers folder then-->Right click->Add-->controller-->ok.then after come to controller.cs page
and that code view Are:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCdemo.Controllers
{
    public class helloController : Controller
    {
        //
        // GET: /hello/

        public ActionResult Index()
        {
            return View();
        }

    }
}









然后右键单击ActionResult - > Addview - > oncheck主页 - > ok

然后来到索引页面。该代码: -











then after right click in ActionResult -->Addview-->oncheck master page-->ok
then come to index page .that code:-



<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title>
</head>
<body>
    <div>
    Hello World!!!!
    </div>
</body>
</html>









但是当我跑步的时候页面不打印到hello world !!!它是默认主页我的MVC页面!

plz帮助我的消息如何!!!





but when i am run the page is not print to hello world!!! it comes default home page "MY MVC Page!"
plz help how to come my msg!!!

推荐答案

You have to set The Startup Page in your Project

1) Go To Project Properties
2) Click Web Tab
3) set Specific Page url as index
4) save the Properties
5) Run the Application now


您好,



您必须配置路由器部分。转到路由器部分并设置控制器

操作根据您的要求进行方法。以这种方式设置



Hello ,

You have to Configure the Router Section . Go to Router Section and Set the Controller and
Action Method according to your requirement. set it lik this way

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

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new
            {
               controller = "hello", //set the controller name here .by Default it is named as "Home"
               action = "Index",
               id = UrlParameter.Optional
            }
        );
    }





谢谢



thanks


namespace MVCdemo.Controllers
{
    public class helloController : Controller
    {
      //
        // GET: /hello/ 
        public ActionResult Index()
        {
            return View();
        } 
      public string Test()
        {
            return "Hello world";
        }
    }
}





现在在浏览器中查看

http:// localhost:49594 / hello /测试

不需要添加视图直接添加视图页面,您可以使用您的方法名称进行网址测试


这篇关于如何在MVC应用程序中打印Hello world?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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