2
我想根據用戶在視圖中的選擇將參數發送回控制器。mvc5 razor將參數發送給控制器
這是我的觀點:
@model IEnumerable<Users>
@{
ViewBag.Title = "FieldSaver Users";
}
<h2>Users</h2>
@foreach(char c in ViewBag.Alphabet)
{
@Html.ActionLink(c.ToString(), "Home/" + c, new object { }, new { @class = "alphabet", @letter = c })
}
<div class="table-responsive">
<table class="table table-striped">
<tr>
<td>Username</td>
<td>First name</td>
<td>Last name</td>
</tr>
@foreach (var user in Model)
{
<tr>
<td>@user.UserName</td>
<td>@user.FirstName</td>
<td>@user.LastName</td>
</tr>
}
</table>
</div>
這是控制器:
public ActionResult Home(string letter)
{
ViewBag.Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
using (var db = new App.Models.DbContext())
{
List<Users> users = (from p in db.Users
select p).ToList();
return View(users);
}
return View();
}
所以,當有人點擊字母表中的鏈接的信,我想將值發送回控制器,當前回發正在發生,但字母參數爲空。
任何想法我做錯了什麼?
感謝,Laziale
可以去掉滾動條? – 2014-10-27 19:46:41
謝謝@DLeh和hutchonoid – Laziale 2014-10-27 19:47:52