Here's ans Scenario: I have a couple of ViewModels, for example:
public class ThreadEditorView { public int ForumID { get; set; } public ThreadEditorPartialView ThreadEditor { get; set; } public ThreadEditorSpecial ThreadSpecial { get; set; } }
Now I have a view:
@using (Html.BeginForm("NewThread", "Thread", FormMethod.Post, new {@enctype="multipart/form-data"})) { @Html.ValidationSummary(true) <fieldset> @Html.Partial("_ThreadEditor", Model.ThreadEditor) @Html.Partial("_SpecialProperties", Model.ThreadSpecial) <p> <input type="submit" value="Create" /> </p> </fieldset> }
Question: how to transfer data from partial representations to the controller? I know that I can just do this:
public ActionResult NewThread(ThreadEditorView modelEditor, ThreadEditorPartialView blabla, ThreadEditorSpecial zumg)
But it doesn’t look very convenient, I would like to pass everything to ThreadEditorView.
Update: SpecialView
@model Vaniv.Core.ViewModel.Forums.ThreadEditorSpecial <div class="editor-label"> @Html.LabelFor(model => model.IsSticky) </div> <div class="editor-field"> @Html.RadioButtonFor(model => model.IsSticky, false) @Html.ValidationMessageFor(model => model.IsSticky) </div> (some irrevalnt forms) <div class="editor-field"> @Html.EditorFor(model => model.IsLocked) @Html.ValidationMessageFor(model => model.IsLocked) </div>
And the editor:
@model Vaniv.Core.ViewModel.Forums.ThreadEditorPartialView <legend>ThreadEditorPartialView</legend> @Html.HiddenFor(model => model.ForumID) <div class="editor-label"> @Html.LabelFor(model => model.ThreadName) </div> <div class="editor-field"> @Html.EditorFor(model => model.ThreadName) @Html.ValidationMessageFor(model => model.ThreadName) </div>
(some forms that are disordered)
</div> <div class="editor-label"> @Html.LabelFor(model => model.Message) </div> <div class="editor-field"> @Html.TextAreaFor(model => model.Message) @Html.ValidationMessageFor(model => model.Message) </div>
asp.net-mvc asp.net-mvc-3
Łukasz Baran
source share