asp.net mvc-使用Javascript获取mvc表单数据
asp.net mvc - Get MVC Form Data Using Javascript
我使用MVC有以下表单:
@using (Html.BeginForm())
{
<div class="editor-label">
@Html.LabelFor(m => m.Title)
</div>
<div class="editor-field">
@Html.TextBoxFor(m => m.Title)
@Html.ValidationMessageFor(m => m.Title)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Description)
</div>
<div class="editor-field">
@Html.TextAreaFor(m => m.Description)
@Html.ValidationMessageFor(m => m.Description)
</div>
<div class="editor-label">
@Html.LabelFor(m => m.Icon)
</div>
<div class="editor-field">
@Html.RadioButtonFor(m => m.Icon, "http://maps.google.com/mapfiles/ms/icons/red-pushpin.png", new { @checked = "checked" }) <img src="http://maps.google.com/mapfiles/ms/icons/red-pushpin.png" alt="red pusphin" />
@Html.RadioButtonFor(model => model.Icon, "http://maps.google.com/mapfiles/ms/icons/red-pushpin.png") <img src="http://maps.google.com/mapfiles/ms/icons/blue-pushpin.png" alt="blue pushpin" />
</div>
}
如何使用javascript检索数据?
我尝试了以下操作,但似乎不起作用:
document.getElementsByName('Title').value;
尝试这个
document.getElementById('Title').value;
检查这个小提琴
http://dotnetfiddle.net/t67Q3G
将所有控件的ID定义为:
@Html.LabelFor(m => m.Title,new{@ID="YOUR ID"})
按id获取值为:
$("#YOUR ID").val();
如果您需要从模型到javascript的值,您可以简单地执行此操作。
function showpopup()
{
var model = @Html.Raw(Json.Encode(Model));
alert(model.Title);
}
相关文章:
- 表单未使用 MVC 提交任何值 Asp.Net
- ASP MVC复选框表单提交问题
- 如何将整个模型集附加到表单数据中,并在MVC中获得它
- asp.net mvc中的javascript验证不适用于登录表单
- 在带有 bootbox 的自定义对话框中添加选项以选择表单控件.js在 ASP.NET MVC 中
- 使用Html.BeginFrom在ASP.Net MVC中提交一个带有锚(<a>)标记且具有一定值的表单
- 在带有Partial视图的MVC 5中,将提交按钮移动到表单外部
- jquery禁用表单提交时输入MVC 4
- ExtJS MVC 表单引用
- 在标准mvc表单帖子中包含knockoutjs可观察值的任何方式
- MVC表单在阅读智能卡后自动发布
- ASP.NET MVC表单:可以用ENTER键提交,但不能用submit按钮提交
- 用MVC表单Post发送HTML字符串
- 使用Javascript函数防止MVC表单提交
- 用jQuery序列化MVC表单
- 没有表单提交的MVC表单验证
- 取消MVC表单提交
- asp.net mvc-使用Javascript获取mvc表单数据
- 不会提交带有名称的 MVC 表单输入按钮
- mvc表单中的取消按钮