0

How can I call a ViewResult controller action/method from jquery/javascript using something similar to the following code:

Index.cshtml (callback for multiselect):

  <script type="text/javascript">
        $("select").multiselect({
            click: function (event, ui) {
                // item selected
                //
                // Also, not sure how I can pass in values from a multiselect to update my grid
                // ...using ajax or post???
                $.post(
                    '@Url.Action("Index","Main")'); 
                     //, { value: ui.value, state: ui.checked ? 'checked' : 'unchecked' });
                     // call my index() and get values or pass in values from multiselect
                // or...
                $.ajax(
                   { url: '@Url.Action("Index","Main")'...// }
                    //, { value: ui.value, state: ui.checked ? 'checked' : 'unchecked' });
                    // call my index() and get values or pass in values from multiselect
                                })
            }
        });
</script>

Controller:

 // GET: /Main/
    public ViewResult Index(/* not sure if possible */ 
         /* get values from multiselect */
         string[] MultiselectId)
    {
        // Populate default grid view
        IList<CModel> cs = db.CModels.OrderByDescending(x => x.CName).ToList();

       // get values in #multiselect and filter grid contents based on that filter value
       // if a filter was selected...

       return View(cs);
    }

1 Answer 1

2
 $("select").multiselect({
            click: function (event, ui) {                
                $.post('@Url.Action("Index","Main")',{value:ui.value},function(data){
                //refresh the grid here                  
                },'json');               
             }
          });

your controller would look like

[HttpPost]
public ActionResult Index(string value){

 return Json(new{data="yourdata"});
 }
Sign up to request clarification or add additional context in comments.

Comments

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.