0
我想知道在MVC中編寫索引方法的最佳方式,因爲我們需要在將模型傳遞給視圖之前對其進行更改。MVC index model with viewmodel
我從某個地方選擇了一種技術,您可以將模型傳遞給您想要傳遞給您的視圖的模型,並對其進行更改,但我們注意到模型綁定在傳遞給索引方法時啓動,當沒有必要的時候發生火災,因爲這是最初的負載。
例如,這是更正確的:
public ActionResult Index(ViewModel model)
{
model.SomeProperty = "MyNewValue";
return base.Index(model);
}
OR
public ActionResult Index()
{
ViewModel model = new ViewModel();
model.SomeProperty = "MyNewValue";
return base.Index(model);
}
,是有什麼我應該知道使用其中任何一方的影響?