下面是索引操作的视图
@model IEnumerable<WorkPlaceBullying.Models.Question>
@{
ViewBag.Title = "Survey Questions";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Questions</h2>
@if (!Model.Any())
{
<p>We don't have any Questions yet!.</p>
}
@Html.ActionLink("Question", "New", "Question", "", new { @class = "btn btn-primary" })
@using (@Html.BeginForm("Index", "Question", FormMethod.Get))
{
@Html.AntiForgeryToken()
<div class="">
<table class="table table-striped table-hover ">
<thead>
<tr>
<td>ID</td>
<td>Questions</td>
<td>Category</td>
</tr>
</thead>
@foreach (var question in Model)
{
<tr>
<td>@question.Id</td>
<td>
@*@Html.ActionLink(@question.SurveyQuestion, "Edit", "Question", new { id = @question.Id }, null)*@
@question.SurveyQuestion
</td>
<td>
@question.QuestionCategory.QuestionCat
</td>
@if (@question.QResponseCategory.Id == 1)
{
<td>
@*@Html.Hidden("Weight", @question.ResponseCategoryId)*@
@Html.DropDownList("Weight", (IEnumerable<SelectListItem>)ViewBag.ResponseId, "Select Response", new { @class = "form-control" })
</td>
<td>
<input type="text" id="Weight" name="__Weight" class="form-control col-sm-2" value="">
</td>
}
</tr>
}
</table>
</div>
}
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
$("#Weight").change(function (evt) {
$('input[name=__Weight]').val($("#Weight").val());
});
});
</script>
}
我成功地将所选项目的值输入到文本字段中,但它填充在所有字段中。如何使每个文本字段唯一并具有自己的选定值?
下面是图形视图
从上图中可以看出……问题1中选择的项目的权重为2。当为其他问题选择项目时……它不会反映在文本框中,而是……它反映了所有文本框中问题1的权重值。