0

I am trying to convert my spark views to use ViewData.Model instead of the namevaluecollection so that I can use AutoMapper to map my dto's to entities before it gets into my action method.

I can access the viewdata.model from the view, but upon posting back the data, viewdata.model is null. here is some sample code:

in my view: <viewdata Message="string" model="MyDto" /> ${Model.Id} < -- displays MyDto.Id

In my filter on the server I am trying to do: var model = filterContext.Controller.ViewData.Model;

but ViewData.Model is null. This is during OnActionExecuted. Is there a trick to get the ViewData.Model to grab the values from the posted view?

zero323
  • 322,348
  • 103
  • 959
  • 935
Sean Chambers
  • 8,572
  • 7
  • 41
  • 55

1 Answers1

0

This has nothing to do with Spark or AutoMapper. You need to learn MVC model binders (for example here).

public ActionResult Action(MyDto dto)
{
   // here dto is filled with values - automatically - if you have corresponding input fields
}
queen3
  • 15,333
  • 8
  • 64
  • 119
  • I got it now. I have been using asp.net mvc for awhile, and monorail before that. I just didn't know that the ViewData.Model was for output only. Previoulsy I only used the namevaluecollection dictionary for extracting data on the view – Sean Chambers Nov 06 '09 at 16:43