我认为:
<% using (Html.BeginForm("SaveRecommendedUserDetails", "Recommend", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ %>
<% foreach (var group in Model.Results)
{ %>
<div id="group-select<%: group.GroupId %>" style="width:auto; height:50px; border:solid 1px black; margin:5px;" >
<h3> <a href="javascript:OnGroupClicked(<%: group.GroupId %>)" id="changer<%: group.GroupId %>"><%: group.Name %></a></h3>
</div>
<% } %>
{
JS:
<script type="text/javascript">
function OnGroupClicked(groupId) {
var groupIds = new Array();
$("#changer" + groupId).on("click", function (e) {
e.preventDefault();
var body = $('#group-select' + groupId),
green = "rgb(0, 128, 0)",
white = "rgb(255, 255, 255)";
if (body.css("backgroundColor") !== green) {
groupIds.push(groupId);
body.css("backgroundColor", green);
} else {
groupIds.pop(groupId);
body.css("backgroundColor", white);
}
});
}
</script>
我的控制器:
[HttpPost]
public ActionResult SaveRecommendedUserDetails(RecommendedUserDataModel model)
{
var userId = ZincService.GetUserIdByEmail(model.Email);
model.UserId = userId;
ZincService.SaveRecommendedUserDetails(model);
return RedirectToAction("Index");
}
推荐用户数据模型
public class RecommendedUserDataModel
{
public int UserId { get; set; }
public string Email { get; set; }
public string Firstname { get; set; }
public string Surname { get; set; }
public string Department { get; set; }
public string JobTitle { get; set; }
public IEnumerable<DataModels.Group.GroupDataModel> Groups { get; set; }
}
我的问题是,如果它被“选中”,我需要将 groupId 返回到控制器,因此单击它。请问我该怎么做?