[英]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.