This is a migrated thread and some comments may be shown as answers.

Issue in Invoking different controller actions based on radio(non kendo) selection

1 Answer 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkata
Top achievements
Rank 1
Venkata asked on 26 Jun 2020, 03:44 PM
Hi Friends,

I facing some issue while binding the data with kendo grid

Aim : I want to call different action methods on radio button (s) selection (not kendo radio buttons) selection , my controller action will fetch the data from DB and return through Json. and binding the kendo grid with the resulted data

Issue : controller action is not being invoked.on second radio button selection 

below are my code bits

.cshtml 

switch (TempData["redirect"].ToString())
            {
                case "All": //
                    actionName = "ABC";
                    break;
                case "CurrentUser": // 
                    actionName = "XYZ";
                    break;
                 default:
                 actionName = "PQR";
                    break;
            }

 <label class="control-label font-weight-bold rumaila-label">All Users: </label>
            <input checked="checked"
                   id="radio"
                   name="radio"
                   type="radio"
                   value="All" 
                   onchange="radioButtonSelected()"
                  />
            <label class="control-label font-weight-bold rumaila-label ml-3">Current User: </label>
            <input 
                   id="radio"
                   name="radio"
                   type="radio"
                   value="CurrentUser" 
                   onchange="radioButtonSelected()"
                  />

.Read(read => read.Action(actionName(getting dynamically through tempdata), "controller name").Data("radioButtonSelected"))

function radioButtonSelected() {
        return {
            id: $("input:radio[name=radio]:checked").val()
        };

below Jquery to send the control to action method to get the actionName(same name will be used above in the grid) 

 $('input[type=radio][name=radio]').change(function() {
        if (this.value == 'All') {
            $.post('@Url.Action("ActionMethod", "Controller", new {id = "All" })', function( data ) {
            });
        }
        else if (this.value == 'CurrentUser') {
            $.post('@Url.Action("ActionMethod", "Controller", new {id = "CurrentUser" })', function( data ) {
            });
        }

.cs

public async Task<ActionResult> ActionName([DataSourceRequest]DataSourceRequest request)
        {
            DataSourceResult resultFinal = null;
            string url = "api/xyz";
            able to get the data from API --- through above url

            return Json(new
            {
                Data = resultFinal.Data,
                Total = resultFinal.Total,
                AggregateResults = resultFinal.AggregateResults,
                Errors = resultFinal.Errors,
            });
        }

unable to invoke the 2nd controller action based on radio selection , first action is being invoked , 2nd controlleraction method is also same as above but some logic change to get data

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 30 Jun 2020, 09:51 AM

Hello,

The provided code does not seem to be related with Kendo Grid but rather a MVC issue and it is not quite clear why the controller is not being hit. You may try to debug the client code and check if the request is event performed. If yes then it has to have correct parameters otherwise the logic in the controller will not be invoked correctly.

If you still observe the issue please try to isolate it in some runnable sample so we could inspect it and be more helpful.

Regards,
Plamen
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
Grid
Asked by
Venkata
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or