【发布时间】:2019-08-07 07:22:14
【问题描述】:
我的 HTML 代码在这里:
<table>
<tr>
<td>
@Html.DropDownList("Statues", (SelectList)ViewBag.UserType, string.Empty, new { @class = "NewIDCn",@id = "name1" })
</td>
<td>
<a class = "UpdateU" href="@Url.Action("Update", "UserPromoted", new { id = item.UserID})">Update</a>
</td>
</tr>
<tr>
<td>
@Html.DropDownList("Statues", (SelectList)ViewBag.UserType, string.Empty, new { @class = "NewIDCn",@id = "name2" })
</td>
<td>
<a class = "UpdateU" href="@Url.Action("Update", "UserPromoted", new { id = item.UserID})">Update</a>
</td>
</tr>
</table>
我的脚本在这里,
<script type="text/jscript">
$(document).ready(function () {
var i = 0;
$('.NewIDCn').each(function () {
i++;
var newID = 'name' + i;
$(this).attr('id', newID);
$(this).val(i);
});
});
$(function () {
$('.UpdateU').click(function () {
var name = $('#name').val();
this.href = this.href + '?UserType=' + encodeURIComponent(name);
});
});
</script>
我的控制器在这里:
public ActionResult Update(string id, string UserType)
{
query = "UPDATE tblUserRegister SET UserType = ' " + UserType + "' WHERE (UserID = '" + id + "')";
cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
}
这个document.ready函数用于自动增加动态idname(name1,name2)。
当我点击 url 动作时,雕像 id 会返回到 usertype functune 中的 id name。我该怎么做呢?
并在控制器中返回 id 名称和用户类型?
【问题讨论】:
标签: javascript asp.net asp.net-mvc asp.net-mvc-4 asp.net-mvc-3