简体   繁体   中英

How do I pass in multiple parameters to a controller?

I am creating a simple search feature in my application and I want to use KendoUI MultiSelect. I need to pass the parameters into the controller but it will only pass the first one you select not them all. How can I pass multiple parameters into my controller? or is my approach incorrect for this type of thing?

Here is my code.

The view:

@using (Html.BeginForm())
{       
    @(Html.Kendo().MultiSelect()
    .Name("vessel_type")            
    .Placeholder("-- Type --")
    .AutoBind(false)            
    .BindTo(new List<string>() {
            "AHTS",
            "PSV",
            "Tug"
          }))

    <input type="submit" value="Search" />
}

My Controller:

public ActionResult Index(string vessel_type)
    {
        var thevessels = from o in db.tbl_vessels
                         select o;

        if (!String.IsNullOrEmpty(vessel_type))
        {
            thevessels = thevessels.Where(x =>
                x.vessel_type.Contains(vessel_type));
        }

        return View(thecvessels);            

    }       

As you can see I am accepting the string from vessel_type but I need it to take as many as the user chooses as there can be more than one. Any ideas?

Many thanks

Though it may not be the cleanest solution you could use $('#vessel_type').data('kendoMultiSelect').value() then concat the results into a string and ajax them down to your controller. Have you tried using string[] vessel_type yet?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM