Why can not I assign the value of the declared @model directive directly without using helpers, like so

@model site.Models.PageNews Controllers.NewsController dataControllerNews = new Controllers.NewsController(); Model.MenuNews = dataControllerNews.OneUpdateMenuNews(new Models.MenuPanelNews()); 

gives an error message

System.Web.Mvc.WebViewPage.Model.get returned null.

Or as it is still possible.

    1 answer 1

    You are trying to assign a value to a property of a model object that has not yet been initialized. Naturally get an exception.

    On good, value for Model should be appropriated in the controller on the server. After that, the page is rendered and sent to the browser.

    What you are doing (creating a controller and getting a model in a view) at least violates the MVC principle. Each component of this pattern should do its own thing.

    • Well, I have the following question, if I create a global @model directive with a specific data type and I have two Html.BeginForm on the page, then when sending data to the methods on the server, the GLOBAL DIRECTIVE reads and sends only the data in the processed form a parameters entered from another form in the same directive NO, it can be solved or you have to sculpt everything into one Html.BeginForm - SergD29