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