所以我有一個(gè)視圖模型:public class ClientViewModel{ public int ClientID { get; set; } [Required] [DisplayName("Client Name")] public string Name { get; set; } [Required] [DisplayName("Client Surname")] public string Surname { get; set; }}以及我使用此視圖模型的視圖(用于搜索客戶列表的按鈕、用于按姓名對(duì)客戶進(jìn)行排序的按鈕和用于按姓氏對(duì)客戶進(jìn)行排序的按鈕):@model IList<ClientViewModel>@using (Html.BeginForm("Index", "Client", FormMethod.Post)){@Html.AntiForgeryToken()<div class="form-horizontal"><div class="form-group"> <label class="control-label col-md-2">Enter client info:</label> <div class="col-md-10"> <input type="text" id="clientInfo" name="clientInfo" value="@Session["input"]" /> </div></div><div class="form-group"> <div class="col-md-offset-2 col-md-10"> <input type="submit" name="command" value="Search Client" class="btn btn-default" /> </div></div><div class="form-group"> <div class="col-md-offset-2 col-md-2"> <input type="submit" name="command" value="Sort by client name" class="btn btn-default" /> </div> <div class="col-md-2"> <input type="submit" name="command" value="Sort by client surname" class="btn btn-default" /> </div></div></div><table class="table"><tr> <th> @Html.DisplayNameFor(model => model[0].Name) </th> <th> @Html.DisplayNameFor(model => model[0].Surname) </th></tr>假設(shè)最初的客戶是:Name SurnameAdam GnbBrandon CookKevin GingerPatrick Star現(xiàn)在,當(dāng)我在 clientInfo 輸入文本框中輸入“g”并單擊搜索按鈕時(shí),它會(huì)使用我輸入的關(guān)鍵字正確顯示客戶端。輸出是:Name SurnameAdam GnbKevin Ginger現(xiàn)在,當(dāng)我單擊“按客戶姓氏排序”時(shí)。所需的輸出是:Name SurnameKevin GingerAdam Gnb但是由于某種原因,post 方法中的 clients 參數(shù)持有客戶“Adam Gnb”和“Brandon Cook”。這就是為什么輸出是:Name SurnameBrandon CookAdam Gnb似乎從視圖返回 IList 并沒有保存當(dāng)前顯示的客戶端。真的不知道如何解決這個(gè)問題。
- 1 回答
- 0 關(guān)注
- 184 瀏覽
添加回答
舉報(bào)
0/150
提交
取消