【发布时间】:2010-09-27 11:24:14
【问题描述】:
我是 ASP.Net MVC 和 jQuery 的新手,我想做的是创建一个表单,根据 rockbandid 是否为空 guid,添加新的 RockBand 或更新现有的 RockBand。我认为现在是开始使用 jQuery 的好时机。所以第一步是制作一个乐队列表,并在它旁边放一个编辑链接。如果用户单击编辑链接,我想更改输入框和隐藏字段的值。下面的代码是第一步,尝试设置输入框的值(暂时使用固定字符串,但最终将是乐队名称)。但是,当我这样做时,我得到了一个需要对象的错误。 (jQuery 包含在 Site.Master 上)
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript">
function fillinbandname(thebandname) {
$('#bandname').val(thebandname);
}
</script>
<ul>
<%foreach (DomainModel.RockBand rockband in ViewData.Model) %>
<%{ %>
<li><%=rockband.BandName %> <a href='javascript:fillinbandname("somesamplevalue");'>edit</a></li>
<%} %></ul>
<%Html.BeginForm("MakeOrUpdateRockBand", "Bands", FormMethod.Post); %>
<input type="text" id="bandname" name="bandname" maxlength="30" />
<input type="hidden" id="bandid" name="bandid" value="00000000-0000-0000-0000-000000000000" />
<input type="submit" value="Add New Band" />
<%Html.EndForm(); %>
</asp:Content>
感觉就像我非常接近......但缺少一些基本的东西。
【问题讨论】:
标签: jquery asp.net-mvc