开发者

Getting at ViewData.Model from spark template post

I am trying to convert my spark views to use ViewData.Model inst开发者_StackOverflow中文版ead 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?


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜