我有包含兩個的ViewModels訪問多個視圖模型
public class SalesByBrandParentVM
{
public IEnumerable<SPSalesbyBrandModel> SpSalesByBrandModel { get; set;}
public ReportSalesbyBrandVM ReportSalesByBrandModel { get; set; }
}
我的看法是這樣的一個視圖模型類:
@model MyStoreReports.ViewModels.SalesByBrandParentVM
@{
ViewBag.Title = "Sales by Brand Page";
}
@section Styles {
<link href="@Url.Content("~/css/report.css")" rel="stylesheet" type="text/css" />
}
<div class="row" >
<div class="col-lg-2">
<form method="post">
<h2>Sales by Brand</h2>
<input asp-for="FromDate" class="form-control" type="date" />
<div class="form-group">
<label asp-for="FromDate">FromDate</label>
<span asp-validation-for="FromDate" class="text-muted"></span>
</div>
<input asp-for="ToDate" class="form-control"type="date"/>
<div class="form-group">
<label asp-for="ToDate">ToDate</label>
<span asp-validation-for="ToDate" class="text-muted"></span>
</div>
<div class="form-group">
<a asp-controller="App" asp-action="Index" class="btn btn-default">Cancel</a>
<input type="submit" value="Submit" class="btn btn-success" />
</div>
</form>
</div>
</div>
<div>
<table>
<tr>
<th>ClientCode</th>
<th>TrxAmount</th>
</tr>
@foreach (var item in Model.SpSalesByBrandModel)
{
<tr>
<td>@item.ClientCode</td>
<td>@item.TrxAmount</td>
</tr>
}
</table>
</div>
public class SPSalesbyBrandModel
{
[Key]
public string ClientCode { get; set; }
public double TrxAmount { get; set; }
}
public class ReportSalesbyBrandVM
{
[Required]
public DateTime FromDate { get; set; }
[Required]
public DateTime ToDate { get; set; }
}
[HttpPost]
public IActionResult ReportSalesbyBrand(ReportSalesbyBrandVM viewmodel)
{
var fdate = viewmodel.FromDate;
var edate = viewmodel.ToDate;
var category = viewmodel.Category;
return View(_totalSalesRepository.GetSalesbyBrand(fdate,edate,category));
}
在表內,我能夠指向SpSalesByBrandModel模型類。 有沒有辦法指向FromDate和ToDate控件ReportSalesByBrandBodeModel viewmodel
在此先感謝!
如果您共享的ViewModels也將是有益的屬性。 –
用viewmodel和控制器方法更新了問題 – Maria