我想通过 Html.ActionLink 方法将模型和下拉列表中选择的值/项目中的一些值传递到控制器中,但找不到任何合适的方法。我在下面给出我的代码 -
看法:
@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 是一个枚举。对于控制器中的状态变量,我总是为空。谁能告诉我这样做的方法。如果 JQuery 是解决方案,那么请举一个例子,因为我是 JQuery 的新手。