javascript - 使用 Javascript 获取 MVC 表单数据

标签 javascript asp.net-mvc asp.net-mvc-3

我使用 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;

检查这个 fiddle

http://dotnetfiddle.net/t67Q3G

关于javascript - 使用 Javascript 获取 MVC 表单数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23151811/

相关文章:

asp.net - 使用 ASP.NET MVC 进行模型绑定(bind)内部嵌套模型

javascript - 确定字符串是对本地文件还是外部文件的引用

javascript - 不返回带有通过 JavaScript 中的 ajax 填充的选项的选择对象

c# - 如何使用 ASP.NET MVC 5 访问 Facebook 个人资料信息

javascript - JavaScript block 中的 @ 符号

asp.net-mvc-3 - MVC3——使用 Jquery 添加附加项目到 List<>

javascript - 在 Express 上保持 mysql 连接

javascript - Highstock 图表 - JSON 输入不起作用

c# - Orchard 在驱动程序中保留 View 模型

c# - 如何排列表格中的项目 - MVC3 View (Index.cshtml)