Question

I have done a few examples in MVC wherein I was declaring my DB in models, then I create my controller and then link a view to each of the methods in Controller.

I have been reading all the net that MVC is loosely coupled. Can you please give me solution on how to generate a View alone for a project without having any models declared.

Was it helpful?

Solution

Just don't use a model in your view:

Controller

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

View (Index.cshtml)

@{
    ViewBag.Title = "Home Page";
}

<h1>Hello World!</h1>
The date of today is: @DateTime.Now.ToShortDateString()

OTHER TIPS

Don't Include a model in your View controller:

public ActionResult ViewName()
{
return View();

}

View:

your HTML code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top