0

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

1 Answer 1

1

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();
        });
    });
Sign up to request clarification or add additional context in comments.

2 Comments

oohh... i see... i made it like this b.ClientSideEvents.Click = string.Format("function(s, e) {{ window.location = '{0}?key={1}'; }}", DevExpressHelper.GetUrl(new { Controller = "ViewPrincipal", Action = "EditRecord",id=c.KeyValue.ToString() }), c.KeyValue.ToString());
If you want to follow your original approach, changing window.location = '{0}?key={1}'; to window.location = '{0}?id={1}'; should also work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.