我使用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;
答案 0 :(得分:1)
答案 1 :(得分:0)
将所有控件的ID定义为:
@Html.LabelFor(m => m.Title,new{@ID="YOUR ID"})
通过id获取价值:
$("#YOUR ID").val();
答案 2 :(得分:0)
如果您需要从模型到javascript的值,您可以直接执行此操作。
function showpopup()
{
var model = @Html.Raw(Json.Encode(Model));
alert(model.Title);
}