ActionLink help !! Required to open edit page .not jqgrid form

Nov 3, 2013 at 1:48 PM
Hi,

I required to open edit, Create page instead of jqgird form and pass the ID value for editing.

here is the sample code that will open jqgird edit form which is working fine.. I want to modify this code and open Edit.cshtml page with the ID value.
editActionOptions: new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorEditActionOptions() { Url = Url.Action("UpdateCategory"), Width = 400, },
Question 2.

How to lock or disable control using Lib.Web.Mvc. I can only hide the control while editing. but I want to show the value and restrict user to edit it.

Thanking you in advance for you advice.

Regards,
NS
Coordinator
Nov 4, 2013 at 8:41 PM
Hi

Ad. 1

In order to achieve what you need I suggest you disable the built-in edit buton and add your own. First you need some JavaScript which will handle the buton functionality:
var onRedirectEditButtonClick = function() {
    var selectedRowId = jQuery('#gridId').jqGrid('getGridParam', 'selrow');
    if (selectedRowId) {
        window.open('Url.Action("Edit")' + '?id=' + encodeURIComponent(selectedRowId), '_self');
    } else {
        alert('You need to select a row first!');
    }
}
You need to adjust above code with your gridId and proper call to Url.Action(). You might also want to change _self if you don't want to open in the same window or replace '?id=' with '/' depending on how your routing is configured.

Now when you have the JavaScript you just need to call AddNavigatorButton:
.Navigator(new Lib.Web.Mvc.JQuery.JqGrid.JqGridNavigatorOptions() { Search = false, Edit = false, ... },
    ...
).AddNavigatorButton(caption: "Edit", icon: "ui-icon-pencil", onClick: "onRedirectEditButtonClick");
Ad. 2

It can be achieved by adding some HTML attributes. In order to do that you can create yourself a custom attribute:
public class JqGridColumnCustomEditableAttribute : JqGridColumnEditableAttribute
{
    public bool Disabled { get; set; }

    public bool Readonly { get; set; }

    protected override IDictionary<string, object> HtmlAttributes
    {
        get
        {
            if (Disabled)
                return new Dictionary<string, object>() { { "disabled", "disabled" } };
            if (Readonly)
                return new Dictionary<string, object>() { { "readonly", "readonly" } };
            else
                return null;
        }
    }

    public JqGridColumnCustomEditableAttribute(bool editable)
        : base(editable)
    {
        Disabled = false;
        Readonly = false;
    }

    public JqGridColumnCustomEditableAttribute(bool editable, string dataUrlRouteName)
        : base(editable, dataUrlRouteName)
    {
        Disabled = false;
        Readonly = false;
    }

    public JqGridColumnCustomEditableAttribute(bool editable, string dataUrlAction, string dataUrlController) :
        this(editable, dataUrlAction, dataUrlController, null)
    { }

    public JqGridColumnCustomEditableAttribute(bool editable, string dataUrlAction, string dataUrlController, string dataUrlAreaName)
        : base(editable, dataUrlAction, dataUrlController, dataUrlAreaName)
    {
        Disabled = false;
        Readonly = false;
    }
}
You can use this attribute instead of JqGridColumnEditableAttribute and set Disabled or Readonly to true depending on effect which you want to achieve (a readonly element is not editable but gets sent back to the server while disabled element is not editable and is not sent back to the server).
Dec 2, 2013 at 9:17 AM
Hi,

Both my issue is resolved as instructed.

Thank you.