1
這讓我瘋了,我用劍道UI電網在超過6個項目,現在使用的版本2013.1.514.340,我從來沒有任何問題,但今天上午我試圖用一個新的版本2013.2.918.340在新項目上,我有一個主要問題。劍道UI電網傳遞空視圖模型我控制器
有了這個新的項目,我有一個網格,沒有什麼花哨。它所做的是在數據庫中表示一個名爲LogTypes的表,您可以在其中添加,編輯和刪除項目。檢索數據和刪除方法的工作,但create方法讓我空值
下面是截圖
另一個有趣的事情是,更新方法不調用SaveOrUpdate可言。
客戶端驗證也適用。
這裏是我完整的代碼,我希望這裏有人能幫助我:(
我的視圖模型
public class LogTypesPageViewModel
{
public IList<LogTypesViewModel> LogTypes { get; set; }
}
public class LogTypesViewModel
{
public int? LogTypeId { get; set; }
[Required]
public string LogTypeDescription { get; set; }
}
我的控制器
public class LogTypesController : Controller
{
private readonly ILogTypesQuery logTypesQuery;
private readonly ICommandProcessor commandProcessor;
public LogTypesController(
ILogTypesQuery logTypesQuery,
ICommandProcessor commandProcessor)
{
this.logTypesQuery = logTypesQuery;
this.commandProcessor = commandProcessor;
}
public ActionResult Index()
{
var viewModel = new LogTypesPageViewModel
{
LogTypes = logTypesQuery.GetLogTypes()
};
return View(viewModel);
}
public ActionResult GetLogTypes([DataSourceRequest]DataSourceRequest request)
{
var logTypes = logTypesQuery.GetLogTypes();
var result = logTypes.ToDataSourceResult(request);
return Json(result);
}
[HttpPost]
[Transaction]
public ActionResult SaveOrUpdate(LogTypesViewModel viewModel, [DataSourceRequest]DataSourceRequest request)
{
if (ModelState.IsValid)
{
var command = new SaveOrUpdateLogTypeCommand(
viewModel.LogTypeId,
viewModel.LogTypeDescription
);
if (ModelState.IsValid)
{
commandProcessor.Process(command);
viewModel.LogTypeId = command.LogTypeId;
}
}
var result = new[] { viewModel }.ToDataSourceResult(request, ModelState);
return Json(result);
}
[HttpPost]
[Transaction]
public ActionResult Delete(int logTypeId, [DataSourceRequest]DataSourceRequest request)
{
var command = new DeleteLogTypeCommand(logTypeId);
commandProcessor.Process(command);
return Json(ModelState.ToDataSourceResult());
}
我查看
@model ViewModels.LogTypes.LogTypesPageViewModel
@{
ViewBag.Title = "Log Types";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h1>Log Types</h1>
@(Html.Kendo().Grid(Model.LogTypes)
.Name("grid-log-types")
.Columns(c =>
{
c.Command(commands =>
{
commands.Edit();
commands.Destroy();
}).Width(150);
c.Bound(x => x.LogTypeDescription);
c.Bound(x => x.LogTypeId);
})
.ToolBar(commands => commands.Create())
.Editable(e => e.Mode(GridEditMode.InLine))
.Sortable()
.Scrollable()
.DataSource(d => d
.Ajax()
.Create(create => create.Action("SaveOrUpdate", "LogTypes"))
.Update(update => update.Action("SaveOrUpdate", "LogTypes"))
.Destroy(destroy => destroy.Action("Delete", "LogTypes"))
.Read(read => read.Action("GetLogTypes", "LogTypes"))
.Model(x => x.Id(p => p.LogTypeId))
)
)
有什麼錯我在做什麼?爲什麼它不觸發更新以及爲什麼Create通過空值?
UPDATE
我也嘗試過這樣的
@(Html.Kendo().Grid<ExternalUserManagement.Web.Mvc.Controllers.ViewModels.LogTypes.LogTypesViewModel>()
還不行
我有一個問題,即編輯值將不是我的視圖模型內張貼。但是,如果我的目錄引用了模型本身,它會通過。非常令人沮喪,因爲我總是在視圖中使用viewmodels。 – JoshYates1980