【发布时间】:2017-05-12 03:39:48
【问题描述】:
我正在创建一个 MVC 应用程序,我想在视图之间传递数据。
这是我的第一个观点:
@model ClassDeclarationsThsesis.Models.AddGroupViewModel
@{
ViewBag.Title = "Add Groups";
}
<h2>Add Groups to subjects</h2>
@foreach (var user in Model.Users)
{
if (user.email.Replace(" ", String.Empty) == HttpContext.Current.User.Identity.Name)
{
if (user.user_type.Replace(" ", String.Empty) == 3.ToString() || user.user_type.Replace(" ", String.Empty) == 2.ToString())
{
using (Html.BeginForm("AddGroup", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Create new groups.</h4>
<hr />
@Html.ValidationSummary("", new { @class = "text-danger" })
<div class="form-group">
@{
List<SelectListItem> listItems1 = new List<SelectListItem>();
}
@foreach (var subject in Model.Subjects)
{
listItems1.Add(new SelectListItem
{
Text = subject.name,
Value = subject.name,
Selected = true
});
}
@Html.LabelFor(m => m.subject_name, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.subject_name, listItems1, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(m => m.qty, new { @class = "col-md-2 control-label" })
<div class="col-md-10">
@Html.TextBoxFor(m => m.qty, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" class="btn btn-default" value="Submit" />
</div>
</div>
}
}
if (user.user_type.Replace(" ", String.Empty) == 1.ToString())
{
<p>You do not have enough permissions to enter this page. Contact the administrator.</p>
}
}
}
还有我的控制器:
public ActionResult AddGroup(AddGroupViewModel model)
{
var entities = new ClassDeclarationsDBEntities1();
var model1 = new AddGroupViewModel();
model1.Subjects = entities.Subjects.ToList();
model1.Users = entities.Users.ToList();
// set your other properties too?
if (ModelState.IsValid)
{
return RedirectToAction("AddGroupsQty", "Account");
}
return View(model1);
}
我想要实现的是将下拉列表中的选定项目和此数量变量传递给 AddGroupsQty 视图。我该怎么做呢?在我的 AddGroupsQty 控制器中,到目前为止,我只有一个简单的视图返回。
【问题讨论】:
-
RouteConfig.cs 中是否有通往新视图的路径?或者您是否尝试根据输入的更改值重新显示当前视图?
-
@Mmcgowa3 不,我没有在那里添加任何路线。我只是想根据该视图的输入显示不同的视图。
标签: c# asp.net .net asp.net-mvc model-view-controller