Click here to Skip to main content
15,908,115 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Fast go to controllers folder then-->Right click->Add-->controller-->ok.then after come to controller.cs page
and that code view Are:-

C#
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();
        }

    }
}




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



XML
<%@ 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>




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!!!
Posted
Comments
Animesh Datta 22-May-14 2:48am    
try to config the router section what i have said and let the know if there will any error come

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
 
Share this answer
 
v2
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
 
Share this answer
 
v2
Comments
Member 10385151 23-May-14 3:35am    
this file not in my project!!!
Animesh Datta 23-May-14 6:39am    
Routings are defined under the class RouteConfig.cs . find the file and modify what i have said and run it.
namespace MVCdemo.Controllers
{
    public class helloController : Controller
    {
      //
        // GET: /hello/ 
        public ActionResult Index()
        {
            return View();
        } 
      public string Test()
        {
            return "Hello world";
        }
    }
}


now See in browser
http://localhost:49594/hello/Test
Do not need to add view page from add view direct you can test by url with your method name
 
Share this answer
 
v2
Comments
Member 10385151 22-May-14 2:40am    
hi i did same process but not retuned "hello world" content its returns default home page!!
[no name] 22-May-14 3:43am    
see updated above content

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900