【问题标题】:In MVC method for controller is not called from inside of the Editor Template在 MVC 中,控制器的方法不是从编辑器模板内部调用的
【发布时间】:2019-06-19 17:02:53
【问题描述】:

我需要在Editor Template 内部初始化Kendo.ComboBox。 我已将模板定义如下:

<script>
    function GetReportID() {
        return {
            reportID: 8
        }
    }
</script>

@(Html.Kendo().ComboBox()
                    .DataValueField("ReportPropertyID")
                    .DataTextField("PropertyName")
                    .DataSource(d => d.Read(r => r.Action("PopulateReportProperty", "TestTicketReportProperty").Data("GetReportID()")))) 

这个模板在Kendo.Grid内部渲染:

columns.Bound(p => p.ReportPropertyData).ClientTemplate("#=ReportProperty.PropertyName#").EditorTemplateName("_PropertyNameEditor").Sortable(false).Width(180);

控制器内部需要调用的方法:

[HttpPost]
public ActionResult PopulateReportProperty([DataSourceRequest] DataSourceRequest request, int reportID)
{
    var reportProperty = TicketReportPropertyRepository.GetReportPropertyEntityRepository(reportID);
    ViewData["defaultPropertyEntity"] = reportProperty.First();
    return Json(reportProperty.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}

这个方法没有被调用。

我做错了什么?

【问题讨论】:

  • 你试过 HttpGet 了吗?

标签: asp.net-mvc-4 model-view-controller kendo-grid editortemplates


【解决方案1】:

您的 _PropertyNameEditor 文件是否位于 Views>Shared>EditorTemplates 文件夹中?

您可能还需要对 ViewModel 中的属性执行 [UIHint("_PropertyNameEditor")]。

【讨论】:

    猜你喜欢
    • 2023-03-22
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-27
    相关资源
    最近更新 更多