简体   繁体   English

ASP.NET MVC调用控制器方法DevExpress

[英]ASP.NET MVC Calling Controller Method DevExpress

I'm trying to call a method on the controller but it gives me a null error. 我正在尝试在控制器上调用方法,但它给了我一个空错误。 I was trying to do the getKeyValue on the code but it won't work. 我试图在代码上执行getKeyValue,但无法正常工作。 I don't know what I'm doing wrong. 我不知道我在做什么错。 Thanks for any help. 谢谢你的帮助。

Controller code 控制器代码

public  ActionResult EditRecord(int id)
{
    int x = id;

    return PartialView("~/Views/FileMaintenance/Principal/EditPrincipal.cshtml", PrincipalInfo);
}

DevExpress GridView code DevExpress GridView代码

settings.Columns.Add(column =>
        {
            column.FieldName = "Unbound";
            column.Caption = "Action";
            column.UnboundType = DevExpress.Data.UnboundColumnType.Object;
            column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
            column.ReadOnly = false;

            column.ColumnType = MVCxGridViewColumnType.ButtonEdit;
            column.SetDataItemTemplateContent((c) =>
            {

                Html.DevExpress().Button(b =>
                {
                    b.Name = "btnVE" + c.KeyValue;
                    b.Text = "V/E";
                    b.UseSubmitBehavior = false; // prevent default submit action
                    b.EnableClientSideAPI = true; // add this line if not sure
                    b.ClientSideEvents.Click = string.Format("function(s, e) {{ window.location = '{0}?key={1}'; }}",
                            DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord" }),
                            c.KeyValue.ToString());
                }).GetHtml();
            });
        });

Error 错误

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditRecord(Int32)' in 'WMS_Web.Controllers.FileMaintenance.ViewPrincipalController'. 对于“ WMS_Web.Controllers.FileMaintenance.ViewPrincipalController”中的方法“ System.Web.Mvc.ActionResult EditRecord(Int32)”,参数字典包含一个非空类型“ System.Int32”的参数“ id”的空条目。 An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. 可选参数必须是引用类型,可为空的类型,或者必须声明为可选参数。 Parameter name: parameters 参数名称:参数

You didn't supply the parameter id in the DevExpressHelper.GetUrl method. 您没有在DevExpressHelper.GetUrl方法中提供参数id You need to set it. 您需要设置它。 In the example below I placed a value of 1. I do not understand why you are placing a "key" in the query string when the required is "id". 在下面的示例中,我将值设置为1。我不明白为什么当要求的值为“ id”时,为什么要在查询字符串中放置“键”。 Changing "key" to "id" should also solve your problem. 将“键”更改为“ id”也应解决您的问题。

settings.Columns.Add(column =>     
{
        column.FieldName = "Unbound";
        column.Caption = "Action";
        column.UnboundType = DevExpress.Data.UnboundColumnType.Object;
        column.EditFormSettings.Visible = DevExpress.Utils.DefaultBoolean.True;
        column.ReadOnly = false;

        column.ColumnType = MVCxGridViewColumnType.ButtonEdit;
        column.SetDataItemTemplateContent((c) =>
        {

            Html.DevExpress().Button(b =>
            {
                b.Name = "btnVE" + c.KeyValue;
                b.Text = "V/E";
                b.UseSubmitBehavior = false; // prevent default submit action
                b.EnableClientSideAPI = true; // add this line if not sure
                b.ClientSideEvents.Click = string.Format("function(s, e) {{ window.location = '{0}'; }}",
                        DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord", id = c.KeyValue.ToString() }));
            }).GetHtml();
        });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM