C# 在MVC视图模型中更新SelectList
我一直在开发我的第一个.NETMVC站点 我有一个包含标题和细节项的Viewmodel。作为标题的一部分,用户需要选择一个公司/数据库进行工作,基于此,我对服务器进行ajax回调,以检索标题其余部分的相关列表数据 现在,在我的详细信息中,用户需要能够根据自己的喜好添加和删除行,客户端需要进行内联编辑。这些行还包含将根据我的ajax请求填充的下拉列表,但是,我不想为每一行调用服务器来获取列表数据,而是希望在选择了数据库之后执行此操作,并且只需更新选择列表并将其与每一行一起发送 标题视图模型C# 在MVC视图模型中更新SelectList,c#,asp.net-core-mvc,C#,Asp.net Core Mvc,我一直在开发我的第一个.NETMVC站点 我有一个包含标题和细节项的Viewmodel。作为标题的一部分,用户需要选择一个公司/数据库进行工作,基于此,我对服务器进行ajax回调,以检索标题其余部分的相关列表数据 现在,在我的详细信息中,用户需要能够根据自己的喜好添加和删除行,客户端需要进行内联编辑。这些行还包含将根据我的ajax请求填充的下拉列表,但是,我不想为每一行调用服务器来获取列表数据,而是希望在选择了数据库之后执行此操作,并且只需更新选择列表并将其与每一行一起发送 标题视图模型 pub
public long PrId { get; set; }
public string PrNumber { get; set; }
public int CompanyID { get; set; }
public int SupplierID { get; set; }
public string Justification { get; set; }
public string ExpenseCompany { get; set; }
public string RequestedBy { get; set; }
public bool BookOrder { get; set; }
public DateTime ExpectedDeliveryDate { get; set; }
public string DeliveryAdress { get; set; }
public string Priority { get; set; }
public string CreatedBy { get; set; }
public DateTime CreatedDate { get; set; }
public int Status { get; set; }
public decimal DiscountValue { get; set; }
public decimal DicountPercentage { get; set; }
public decimal TotalExcl { get; set; }
public decimal Vat { get; set; }
public decimal TotalIncl { get; set; }
public string CurrentUser { get; set; }
public string PrevUser { get; set; }
public string EvoPoNum { get; set; }
public List<SelectListItem> Companies { get; set; }
public List<IFormFile> SupportingDocs { get; set; }
public List<IFormFile> DeliveryDocs { get; set; }
public List<PRLinesVM> Lines { get; set; }
public List<SelectListItem> Priorties { get; set; }
public List<SelectListItem> RequestbyUsers { get; set; }
public List<SelectListItem> ExpenseCopanies { get; set; }
public List<SelectListItem> Suppliers { get; set; }
public List<SelectListItem> DeliveryAddresses { get; set; }
public IEnumerable<SelectListItem> TaxTypes { get; set; }
public IEnumerable<SelectListItem> PRProjects { get; set; }
public IEnumerable<SelectListItem> PRDepartments { get; set; }
public IEnumerable<SelectListItem> PRCosts { get; set; }
public int LineId { get; set; }
public string PRCost { get; set; }
public string PRDepartment { get; set; }
public string PRProject { get; set; }
public string Description { get; set; }
public decimal Quantity { get; set; }
public decimal PriceExcl { get; set; }
public decimal PriceIncl { get; set; }
public decimal DiscountPerc { get; set; }
public int TaxType { get; set; }
public IEnumerable<SelectListItem> TaxTypes { get; set; }
public IEnumerable<SelectListItem> PRProjects { get; set; }
public IEnumerable<SelectListItem> PRDepartments { get; set; }
public IEnumerable<SelectListItem> PRCosts { get; set; }
public long PrId { get; set; }
我自己解决了这个问题,只在选定公司后渲染页面的其余部分
关于网格线,我使用局部视图添加线并填充每一行的下拉列表。您的ajax代码在哪里?@Valkyrie您是否建议我将标题和细节的其余部分包装在局部视图中,以便在选择公司后返回整个模型以及所有列表数据?解决方案发布在下面
@model PRHeaderVM
<form asp-action="SubmitPR" role="form" id="WorkgflowForm" style="width: 100%;top:0;right:0;left: 10px; bottom:10px">
<div class="form-horizontal">
<div class="row">
<div class="col-lg-3">
<div class="form-group">
<div style="padding-bottom: 40px;">
<label class="col-lg-4 control-label">Company</label>
<div class="col-lg-8">
<select id="DbDropdown" asp-for="CompanyID" asp-items="@Model.Companies" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
<div style="padding-bottom: 20px;">
<label class="col-lg-4 control-label">Supplier</label>
<div class="col-lg-8">
<select id="SuppDropdown" asp-for="SupplierID" asp-items="@Model.Suppliers" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
<label class="col-lg-4 control-label">Jutification</label>
<br />
<div class="col-lg-8">
<textarea id="Jutification" asp-for="Justification" class="form-control" rows="4">
</textarea>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<div style="padding-bottom: 40px;">
<label class="col-lg-4 control-label">Expense Company</label>
<div class="col-lg-8">
<select id="expComp" asp-for="ExpenseCompany" asp-items="@Model.ExpenseCopanies" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
<div style="padding-bottom: 20px;">
<label class="col-lg-4 control-label">Requested By</label>
<div class="col-lg-8">
<select id="Reqby" asp-for="RequestedBy" asp-items="@Model.RequestbyUsers" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
<div style="padding-bottom: 20px;">
<label class="col-lg-4 control-label">
Book order
</label>
<div class="col-lg-8">
<input type="checkbox" id="Bookord" asp-for="BookOrder" class="from-control" style="width:100%;height:30px" />
</div>
</div>
<div style="padding-bottom: 20px;">
<label class="col-lg-4 control-label">
Price Incl
</label>
<div class="col-lg-8">
<input type="checkbox" id="priceincl" class="from-control" style="width:100%;height:30px" />
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<div style="padding-bottom: 40px;">
<label class="col-lg-4 control-label">Expected Delivery Date</label>
<div class="col-lg-8">
<div class="input-group date" data-provide="datepicker">
<input id="datetimepickercustom" type="text" asp-for="ExpectedDeliveryDate" class="form-control" data-date-format="mm/dd/yyyy">
<div class="input-group-addon">
<span class="glyphicon glyphicon-th"></span>
</div>
</div>
</div>
</div>
<div style="padding-bottom: 20px;">
<label class="col-lg-4 control-label">Delivery Address</label>
<div class="col-lg-8">
<select id="DelivDropdown" asp-for="DeliveryAdress" asp-items="@Model.DeliveryAddresses" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
<label class="col-lg-4 control-label">Priority</label>
<br />
<div class="col-lg-8">
<select id="PrioDropdown" asp-for="Priority" asp-items="@Model.Priorties" class="form-control">
<option>Please select</option>
</select>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="btn-group">
<a id="btnaddval" class="btn btn-primary" onclick="addVal('');">
<i class="glyphicon glyphicon-plus"></i> Add Line
</a>
</div>
<table id="myTable" class="table table-bordered table-striped table-condensed" style="height : 450px">
<thead style="width: 100%;display: table-column;table-layout: fixed;">
<tr>
<td style="width:25px"></td>
<td>
PR Cost
</td>
<td>
PR Department
</td>
<td>
PR Project
</td>
<td>
Description
</td>
<td>
Quantity
</td>
<td>
Price(Excl)
</td>
<td>
Discount %
</td>
<td>
Tax Type
</td>
<td>
Price(Incl)
</td>
<td>
.......
</td>
</tr>
</thead>
<tbody id="tbLines" style="height : 400px;position:fixed; overflow-y: scroll;width: 92%;">
@if (Model.PRCosts != null && Model.PRDepartments != null && Model.PRProjects != null)
{
foreach (var item in Model.Lines)
{
item.PRCosts = Model.PRCosts;
item.PRDepartments = Model.PRDepartments;
item.PRProjects = Model.PRProjects;
Html.RenderPartial("_PRDetails", item);
}
}
</tbody>
</table>
</div>
</div>
</form>
</section>