[英]Add data to model on partialview load
Kinda堅持了這一點,但是我非常感謝我從這里向每個人學習的所有知識。 我有一個Webgrid,當您選擇行之一時會加載一個partialview。 顯示公司信息,部分顯示更多詳細信息。 效果很好。
每個公司都被分配了某些用戶,並且可以將用戶分配給多個公司中的多個角色。 我正在嘗試將用戶添加到partialview,以便可以選擇它們進行編輯,但是我所做的每次嘗試在控制器中覆蓋partialview都不會導致更改。 任何建議將不勝感激。
模型
public class Clients
{
[Key]
public int ID { get; set; }
public int EINC { get; set; }
public string CompanyId { get; set; }
public string CompanyName { get; set; }
public ClientUsers[] ClientUserList { get; set; }
public ClientUsers AddedItem { get; set; }
}
public class ClientUsers
{
public string UserName { get; set; }
public string ReportingCompanyID { get; set; }
public Guid UserId { get; set; }
}
視圖
@{
MyName.Models.Clients clients = new MyName.Models.Clients();
}
...
@{
var grid = new WebGrid(Model, canPage: true, rowsPerPage: 30, selectionFieldName: "selectedRow", ajaxUpdateContainerId: "gridContent");
grid.Pager(WebGridPagerModes.NextPrevious);}
<div id="gridContent">
@grid.GetHtml(tableStyle: "webGrid",
headerStyle: "header",
alternatingRowStyle: "alt",
selectedRowStyle: "select",
columns: grid.Columns(
grid.Column("Id", format: (i) => i.GetSelectLink(i.CompanyId), style: "compid"),
grid.Column("CompanyName", "CompanyName", style: "description")
))
@if (grid.HasSelection)
{
clients = (MyName.Models.Clients)grid.Rows[grid.SelectedIndex].Value;
Html.RenderPartial("~/Views/Client/_ClientAdminDetails.cshtml", clients);
}
局部視圖
@model MyName.Models.Clients
<h3>@Model.CompanyName<br /><em>@Model.CompanyId</em></h3>
控制者
// create a List and add query results to it, then add list object to model
// and return to partialview
var q = from a in db.AllowedCompanies
join p in db.CustomUserProfiles
on new { a.CustomUserProfileUserId, a.CustomUserProfileID }
equals new { CustomUserProfileUserId = p.UserId, CustomUserProfileID = p.ID }
where
a.ReportingCompanyID == clients
orderby
p.UserName
// select new ClientUser()
// {
// UserName = p.UserName,
// ReportingCompanyID = a.ReportingCompanyID,
// UserId = p.UserId
// };
// ObservableCollection<ClientUser> userlist = new ObservableCollection<ClientUser>(q.ToList());
看看最后的答案,也可能是有幫助請點擊
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.