简体   繁体   中英

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. 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

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'. 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. 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". Changing "key" to "id" should also solve your problem.

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();
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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