Hello everyone,
I wish to have an MVC application that allows me to have a url like
http://www.somedomain.com/andrew
and then it would display details for andrew.
So far, I have setup my Global.asax like so
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace TestMVC
{
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Root",
"{name}",
new { controller = "Account", action = "Index", name = "" }
);
}
protected void Application_Start()
{
RegisterRoutes(RouteTable.Routes);
}
}
}
And my controller looks like this
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace TestMVC
{
[HandleError]
public class AccountController : Controller
{
public ActionResult Index(string name)
{
ViewData["Name"] = name;
return View();
}
}
}
And my view has
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
<!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>Welcome</title>
</head>
<body>
<div>
Hello <%=ViewData["Name"] %>
</div>
</body>
</html>
At this stage, Name doesn't have a value (even though my url is http://localhost:1057/Andrew)
This application only has 1 controller and 1 view, so I am just wondering how I can get something like this to work as expected.
Dont forget to click "Mark as answer" on the post that helped you.
================================================
Why catch a fish to feed someone, when you can teach them to fish and they can feed themselves