开发者

TextBoxFor<DIFFERENT VIEW MODEL>() for AJAX operation?

I have a view model ViewModel1 that has all of the proerties for my view.

In my view I need 2 text boxes that will be used in a AJAX call to another action that has different parameters then the view I'm currently on.

Here's what I'd like the code to look like:

@using(Ajax.BeginForm("AjaxAction", "Home", new { TestId = Model.TestId }, new BOHAjaxOptions(), new { id = "newform", name = "newform" }))
{
    @Html.TextBoxFor<DIFFERENT VIEW MODEL>(model => model.FIELD1)
    @Html.TextBoxFor<DIFFERENT VIEW MODEL>(model => model.FIELD2)
    <a href="#" onclick="javascript:$('#newform').submit();">Submit</a>
}

I figured this would make sense since I want to be able to use the "AjaxAction" action on different views from different controllers since this action is going to be called from multiple parts on the site.

Or am I just not seeing the right picture here? Shoul开发者_StackOverflow社区d I just include FIELD1 and FIELD2 in all of the ViewModels that need to call this AJAX action?


You should include all the data needed for the view in the view model, including data that might be posted back to another action as a separate model. Note that generally there isn't a one-to-one correspondence between a entity model and a view model. In nearly all cases my view models include either more or less data that the primary entity that the view is focused on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜