这里ANS方案发送数据: 我已经安装的情侣喜欢的ViewModels的:ASP .NET MVC3如何从局部视图
public class ThreadEditorView
{
public int ForumID { get; set; }
public ThreadEditorPartialView ThreadEditor { get; set; }
public ThreadEditorSpecial ThreadSpecial { get; set; }
}
现在我已经和查看:
@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>
}
的问题是如何我是否将部分视图的数据传递给控制器? 我知道我可以简单地这样做:
public ActionResult NewThread(ThreadEditorView modelEditor,
ThreadEditorPartialView blabla, ThreadEditorSpecial zumg)
但是,这不看真的很方便,我想在ThreadEditorView通过一切。
更新: 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>
和编辑:
@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>
(某些形式,是irrevelant)
</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>
我想的是,“不相关领域”可能不是无关紧要......都是这些字段不是“ThreadEditorPartialView”的一部分?你有没有尝试从部分中删除它们,看它是否有效? – 2011-06-08 15:30:54
那些“无用的字段”只是由脚手架生成的,看起来像我发布的那些。我无法删除它们,因为我需要所有这些输入数据。 – 2011-06-08 15:35:01