浏览了有关堆栈溢出和Google的大量文章之后,
我认为问题出在我的模型上, 我尝试了很多事情,例如使所有字段都可编辑,将id的默认值设置为160000等,但是无法使其工作
您能确定一下并让我知道,我应该怎么做才能使这项工作
Kendo网格
@(Html.Kendo().Grid<BuyUpRatesVM>()
.Name("grdBuyUpRates")
.HtmlAttributes(new { style = "width:100%" })
.Columns(columns =>
{
columns.Bound(d => d.RateQuoteBuyUpConfigIdNh).Hidden();
columns.ForeignKey(d => d.ConfigDetlIdNh, (System.Collections.IEnumerable)ViewData["StateIssuer"], "ConfigDetlId", "StateIssuer")
.Title("State/Issuer").HeaderHtmlAttributes(new { title = "State/Issuer" }).HtmlAttributes(new { title = "#= StateHyphenIssuer #" }).Width("20%");
columns.Bound(d => d.EffectiveDate).Title("Effective Date").HeaderHtmlAttributes(new { title = "Effective Date" }).EditorTemplateName("date").Format("{0:MM/dd/yyyy}").HtmlAttributes(new { title = "#= EffectiveDate #" }).Width("20%");
columns.Bound(d => d.ExpirtaionDate).Title("Expiration Date").HeaderHtmlAttributes(new { title = "Expiration Date" }).EditorTemplateName("date").Format("{0:MM/dd/yyyy}").HtmlAttributes(new { title = "#= ExpirtaionDate #" }).Width("20%");
columns.ForeignKey(d => d.RateTypeLookUpId, (System.Collections.IEnumerable)ViewData["RateType"], "RateTypeLookUpIdDD", "RateTypeLookUpValueDD")
.Title("Rate").HeaderHtmlAttributes(new { title = "Rate" }).HtmlAttributes(new { title = "#= RateTypelookUpValue #" }).Width("20%");
columns.Bound(d => d.Amount).Title("Amount").HeaderHtmlAttributes(new { title = "Amount" }).HtmlAttributes(new { title = "#= Amount #" }).Width("20%");
columns.Command(command => { command.Edit(); }).Title("Action").Width(65);
})
.Pageable(p => p.PageSizes(true).Refresh(true))
.ToolBar(tools => tools.Excel())
.Excel(excel => excel
.FileName(@timetstamp)
.Filterable(true)
.ProxyURL(Url.Action("Excel_Export", "Common")).AllPages(true))
.Sortable()
.Editable(editable => editable.Mode(GridEditMode.InLine))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
//.Sort(s => s.Add("StateLookUpName"))
.Update(update => update.Action("UpdateBuyUpRates", controller))
.Model(model =>
{
model.Id(p => p.RateQuoteBuyUpConfigIdNh);
})
.Read(read => read.Action("GetBuyUpRates", controller)))
.Resizable(resize => resize.Columns(true)).AutoBind(true)
)
控制器动作
public ActionResult GetBuyUpRates([DataSourceRequest] DataSourceRequest request)
{
var oob = _configuration.GetBuyUpRates();
DataSourceResult lstArtifact = oob.ToDataSourceResult(request);
return Json(lstArtifact);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateBuyUpRates([DataSourceRequest] DataSourceRequest request, BuyUpRatesVM p_BuyUpRatesVM)
{
if (ModelState.IsValid)
{
if (p_BuyUpRatesVM != null)
{
p_BuyUpRatesVM = _configuration.UpdateBuyUpRates(p_BuyUpRatesVM, StateManager.LoggedUserIdRx);
if (!string.IsNullOrEmpty(p_BuyUpRatesVM.ErrorMessage))
{
ModelState.AddModelError("Error", p_BuyUpRatesVM.ErrorMessage);
}
else
{
return Json(new[] { p_BuyUpRatesVM }.ToDataSourceResult(request, ModelState));
}
}
}
return Json(new[] { p_BuyUpRatesVM }.ToDataSourceResult(request, ModelState));
}
模型类
public class BuyUpRatesVM
{
public decimal RateQuoteBuyUpConfigIdNh { get; set; }
public decimal ConfigDetlIdNh { get; set; }
public decimal ConfigIdNh { get; set; }
public string State { get; set; }
public string IssuerId { get; set; }
public string StateHyphenIssuer { get; set; }
public DateTime EffectiveDate { get; set; }
public DateTime ExpirtaionDate { get; set; }
public decimal RateTypeLookUpId { get; set; }
public string RateTypelookUpValue { get; set; }
public decimal Amount { get; set; }
public string ErrorMessage { get; set; }
}