1

I am moving the views of an old project from ASPX to Razor, I have almost finished with it without any major issues, but I have come to this kind of problem with some strongly typed views. The thing is that when the controller returns the view using

return View(model)

the View Egine finds the proper views, always and for all the controller actions, but the model is always null when the View try to access it. But if I use

return View (ViewName, model) 

Everything works like a charm.

So my question is why is the first option working perfectly when the views are using ASPX and not with Razor?

and

Why is it finding the view but passing a null model?

tereško
  • 58,060
  • 25
  • 98
  • 150
LorenzoGM
  • 13
  • 3
  • 1
    How are you initializing `model`? – Andy Refuerzo Feb 19 '13 at 11:48
  • Well I think that is not the problem, the models contain the proper data when you are in the controller action before returning the view, but once I return the view using return View(model), it is null in the view – LorenzoGM Feb 19 '13 at 12:09
  • 1
    Can you post the method name for `return View(model)`? It should be the same name of the view unless you specify `[HttpPost, ActionName("ViewName")]` – Andy Refuerzo Feb 19 '13 at 12:14
  • For example one action in one of my controller is `public ActionResult Exhibitor( int listingId )` no [HttPost] is the get version of the action. If inside I do `return View(model)` it does find the Exhibitor view but the model is null. If i do `return View("Exhibitor", model)` it works. – LorenzoGM Feb 19 '13 at 12:43

0 Answers0