3
votes

I'm new to ASP.NET mvc and kendo ui framework and have the following issue:

I have a partialview in a window with a multiselect which receives its values out of the database. the view looks like:

@model SoftwareAdminInterface.Models.Administration.Pattern
<div id="myContentPopupEditRole_div">

@using (Ajax.BeginForm("SetCombi", "Pattern", new {  }, new AjaxOptions() { HttpMethod = "post", UpdateTargetId = "myContentPopupEditRole_div" }))
{
    <center>
        <br />
    <table class="table_no_borders">
        <tr>
            <td style="width: 300px">
                @(
                Html.Kendo().MultiSelectFor(model => model.RegExId)
                    .MaxSelectedItems(2)
                    .Name("RegExID")
                    .DataTextField("RegExName")
                    .DataValueField("RegExID")
                    .Placeholder("Select Patterns...")   
                    .AutoBind(false)       
                    .DataSource(source => {
                        source.Read(read =>
                        {
                            read.Action("GetPatternsForCombi", "Pattern");
                        })
                    .ServerFiltering(true);
          })
    )
            </td>
        </tr>
    </table>
        <button class="k-button k-button-icontext k-grid-custom" id="get" type="submit">@Resources.General.BtnSave</button>
    </center>
}   
</div>

I'm using a model which looks like this:

public class Pattern
{
    [ScaffoldColumn(false)]
    public int RegExID { get; set; }

    [Display(Name = "RegEx")]
    [Required]
    public string RegExName { get; set; }

    [UIHint("GridForeignKey")]
    public int CategoryID { get; set; }

    public string CategoryName { get; set; }

    public string ColumnName { get; set; }

    public string RegExTable { get; set; }

    [UIHint("GridForeignKey")]
    public int? TableID { get; set; }

    public string Version { get; set; }

    public string Description { get; set; 

}

in the SetCombi function which is called in the patterncontroller, I only want to receive the two ID's of the selected objects out of the multiselect, but I've no idea how they should be send to the controller.

thx in advance for your help

1
I think you will get values selected in comma separated format. You need to split it and get individual selected values.ckv

1 Answers

5
votes

I think you have two options:

1) Change RegExID to be a string and then I believe they would come across as comma separated values.

2) (The better option) Add a ViewModel which has many of the same properties as your Pattern model above. The main difference for this is that you would have

public List<int> RegExIDs { get; set; }

Then in your controller you would take the new ViewModel as an argument to your post method and parse out the values in the list as necessary.