【发布时间】:2012-07-26 11:25:00
【问题描述】:
我有以下视图模型,它将用于获取问题描述和重新创建问题的步骤。
public class IssueViewModel
{
public string IssueDesc { get; set; }
public string ReCreationSteps { get; set; }
}
查看
@using (Html.BeginForm())
{
@Html.LabelFor(model => model.IssueDescription)
@Html.TextAreaFor(m=>m.IssueDescription)
@Html.LabelFor(model => model.ReCreationSteps )
<div class="editable" id="ReCreationSteps " name="ReCreationSteps" contenteditable="true">
<ol>
<li></li>
</ol>
</div>
<input value="Create" type="submit" />
}
控制器
[HttpPost]
public ActionResult Create(IssueViewModel model)
{
string html = model.Recreation;
//<ol><li>Step:1 Enter the text</li><li>Step:2 Click the button <li></ol>
Issue newIssue = model.ToIssue(); // here value will be splitted and add steps to table
_issueRepository.AddIssue(Issue);
}
我想给用户一个简单的控件来输入问题重新创建步骤。所以我最终将 div 元素的 contenteditable 属性设置为 true。
我已将 ReCreationSteps 绑定到 Div 元素,但它不起作用。提交表单后,我无法在 ReCreationSteps 属性中获取 DIV 的值/html。
任何人都可以帮助我或建议我其他解决方案。
【问题讨论】:
-
HukmChand - 您没有在示例代码中显示您定义表单的位置。你能把它包括进去吗,然后希望它应该更容易解决问题
-
@jimtollan 我已经更新了示例。
-
好的,谢谢,现在看表格。有点疑惑!!。您在 div 中没有
<input>类型,这些是在其他地方动态创建的吗?您能否更详细地说明如何在 div 中填充任何<input>元素。就目前而言,我对您的流程的理解存在巨大差距 -
首先,您没有将 div 绑定到模型,创建一个 div 并在其上放置一个 id 仅适用于客户端。对于要绑定的任何内容,当表单提交回服务器时,该值需要在提交(post 或 get)中。
-
@jimtollan 不,我没有动态加载 div。只是在 View 本身中编码纯 html 并绑定到 ReCreationSteps 属性。我没有任何其他细节。因为我正处于开发阶段试图完成这项工作。
标签: c# asp.net-mvc-3 html binding