我想通过Html.ActionLink方法将模型和dropdownlist选择的值/项中的一些值传递给控制器,但找不到任何合适的方法。我在下面给出了我的代码 -
查看:
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<div class="row">
<div class="span3">
<div class="text-left">@Html.LabelFor(model => model.EntryId)</div>
</div>
<div class="span3">
<div class="text-left">
@Html.DisplayFor(model => model.EntryId)
@Html.HiddenFor(model => model.EntryId)
</div>
</div>
<div class="span3">
<div class="text-left">@Html.LabelFor(model => model.EntryDate)</div>
</div>
<div class="span3">
<div class="text-left">
@Html.DisplayFor(model => model.EntryDate)
</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Check Information</legend>
<div class="row">
<div class="span3">
<div class="text-left">@Html.LabelFor(model => model.Check.CheckId)</div>
</div>
<div class="span3">
<div class="text-left">
@Html.DisplayFor(model => model.Check.CheckId)
@Html.HiddenFor(model => model.Check.CheckId)
</div>
</div>
<div class="span3">
<div class="text-left">@Html.LabelFor(model => model.Check.CheckTitle)</div>
</div>
<div class="span3">
<div class="text-left">@Html.DisplayFor(model => model.Check.CheckTitle)</div>
</div>
</div>
</fieldset>
<fieldset>
<legend>Comments</legend>
<div class="span4">
@Html.ActionLink("Add Comment", "AddComment", new { Model.EntryId })
@Html.ActionLink("View All Comments", "ViewAllComments", new { Model.Check.CheckId })
</div>
<div>
<table class="table table-bordered">
<tr>
<th>
Serial
</th>
<th>
Comment
</th>
<th>
Date
</th>
<th>
Status
</th>
<th>
</th>
</tr>
@for (int i = 0; i < Model.CheckCommentsList.Count; i++)
{
<tr>
<td>
@Html.DisplayFor(modelItem => Model.CheckCommentsList[i].Serial)
@Html.HiddenFor(modelItem => Model.CheckCommentsList[i].Serial)
</td>
<td>
@Html.DisplayFor(modelItem => Model.CheckCommentsList[i].Comment)
@Html.HiddenFor(modelItem => Model.CheckCommentsList[i].Comment)
</td>
<td>
@Html.DisplayFor(modelItem => Model.CheckCommentsList[i].CommentDate)
@Html.HiddenFor(modelItem => Model.CheckCommentsList[i].CommentDate)
</td>
<td>
@Html.DropDownListFor(modelItem => Model.CheckCommentsList[i].CommentStatus, new SelectList(Model.CommentStatusList, Model.CheckCommentsList[i].CommentStatus.ToString()), new {@id="ddlCommentStatus"})
@Html.ValidationMessageFor(model => Model.CheckCommentsList[i].CommentStatus)
@*@Html.HiddenFor(modelItem => Model.CheckCommentsList[i].CommentStatus)*@
</td>
<td>
@Html.ActionLink("Update Status", "UpdateCommentStatus", new { Model.EntryId, Model.CheckCommentsList[i].Serial, Model.CheckCommentsList[i].CommentStatus, Model.Check.CheckId })|
@Html.ActionLink("Delete", "DeleteComment", new { Model.CheckCommentsList[i].Serial, Model.EntryId })
</td>
</tr>
}
</table>
</div>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
控制器:
public ActionResult UpdateCommentStatus(string entryId, int serial, string status, string checkId)
{
var securityInformation = new SecurityInformation();
securityInformation.MemberId = (string)Session["MemberId"];
if (string.IsNullOrEmpty(securityInformation.MemberId))
{
return RedirectToAction("LogIn", "MemberLogIn");
}
var commentStatus = (CommentStatus)Enum.Parse(typeof (CommentStatus), status);
new CheckDataManager().UpdateCheckDataCommentStatus(entryId, serial, commentStatus);
return RedirectToAction("ViewAllComments", new { checkId });
}
请注意,CommentStatus是一个枚举。我总是在控制器中获取状态变量的null。任何人都可以告诉我这样做的方法。如果JQuery是解决方案,那么请举个例子,因为我是JQuery的新手。