kendo-ui-mvc

how do i call the controller in kendo ui grid mvc


How do i call the controller in mvc kendoui grid

here is the code:

but not working:

   .ClientTemplate(string.Format("<a class=\"modal\" rel=\"/address/#= Id #/map\" close=\"{0}\" title=\"{1}\"><img src=\"/content/images/ico_edit_16.png\" /></a>",
                                T("Common.Close").Text,
                                T("Address.MapAddress").Text)

here is the controller:

  public ActionResult AddressMap( int accountId)
    {
        //load default accounts
        var listModel = new AddressListModel();
        //{
        //    AccountId = accountId,
        //    GridPageSize = _commonSettings.GridPageSize,
        //};

        //listModel.Addresses = new List<AddressModel>();
        return View(listModel);
    }

Solution

  • Using your existing code:

       .ClientTemplate(string.Format("<a class=\"modal\" rel=\"/address/#= Id #/map\"    
                         close=\"{0}\" title=\"{1}\"><img src=\"/content/images/ico_edit_16.png\" /></a>",
                                    T("Common.Close").Text,
                                    T("Address.MapAddress").Text)
    

    You will see you are setting the a tag's rel setting rather than the href property.

    so all you should need to do is change the tag so it is more like this:

    (string.Format("<a class='k-link' href='{2}' close='{0}' title='{1}'><img src='/content/images/ico_edit_16.png' />#=Id#</a>",
                                        T("Common.Close").Text,
                                        T("Address.MapAddress").Text, @Url.Action("AddressMap", "{Your Controller}", new {accountId= "#=Id#"})))
    

    All I have done is passed the url into the string formatter and then bound the accountId to the Id that is passed into the row from the dataItem.

    I have also added the Id to the link so you can see what is being presented.

    If this isn't what you wanted then let me know what you actually need and I will amend the answer accordingly