Search code examples
asp.net-mvc-4razorviewmodelscontrollers

Can I create a view in MVC4 (Razor) without having model/ controller like in ASP.NET


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.


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