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.

Était-ce utile?

La 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()

Autres conseils

Don't Include a model in your View controller:

public ActionResult ViewName()
{
return View();

}

View:

your HTML code

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top