[英]Copy a value to EditorFor ASP.Net MVC
Using ASP.Net MVC. 使用ASP.Net MVC。 In Edit mode I have this :
在编辑模式下,我有:
<div class="editor-field">
<%: Html.EditorFor(model => model.Date) %>
<%: Html.ValidationMessageFor(model => model.Date) %>
</div>
and I have a DatePicker using Jquery. 我有一个使用jQuery的DatePicker。
<rhp:DatePicker ID="DatePicker1" runat="server"></rhp:DatePicker>
and I can get the Text of date picker : DatePicker1.Text 我可以获得日期选择器的文本:DatePicker1.Text
When the user pick the date I want picked date to be copied to model.Date and save to database. 当用户选择日期时,我希望将选择的日期复制到model.Date并保存到数据库。 How can I do this?
我怎样才能做到这一点?
If you don't want to create a custom EditorTemplate, the easiest way would be to remove the Html.EditorFor(m => m.Date)
and use your DatePicker as the editor: 如果您不想创建自定义EditorTemplate,最简单的方法是删除
Html.EditorFor(m => m.Date)
并将DatePicker用作编辑器:
<div class="editor-field">
<rhp:DatePicker ID="Date" runat="server"></rhp:DatePicker>
<%: Html.ValidationMessageFor(model => model.Date) %>
</div>
Notice that the ID for the DatePicker control is Date
, which should allow the model binder to bind the value to the Date
property of your model. 请注意,DatePicker控件的ID为
Date
,它应允许模型绑定器将值绑定到模型的Date
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.