I have a ViewModel which holds my InputModel as a property.

I use HTML helpers like so: @Html.TextBoxFor(m => m.InputModel.UserId) for example.

The problem is that this generates: <input name="InputModel.UserId" />

And the model-binder does not populate the properties in my HttpPost method:

public ActionResult Index(InputModel model)

I see there is a generic version of HTML helpers, I was thinking maybe I can leverage that somehow, but I havn`t yet figured out how. Or maybe there is a completley different way around this, that I'm not seeing since I am new to MVC.

有帮助吗?

解决方案

You could either change your action to

public ActionResult Index(ViewModel model)

in which case the model.InputData would be populated or use Bind attribute

public ActionResult Index([Bind(Prefix="InputModel")] InputModel model)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top