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

Gain access to DataValueField Mvc method code behind how

7 Answers 114 Views
MultiColumnComboBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 17 Aug 2020, 07:31 PM

I am about to plan a purchase with a  new customer again for the suite and I am using the latest demo. I was trying to get the value from the form that I placed my control in. I need to gain access in this field  .DataValueField("Id") which would be bound to the form when its posted but when I access tag item its null
  

<form asp-action="LinkToCase" asp-controller="MISObjects">
 
<div class="row">
    <div class="col-md-12">
        <div class="card card-success">
 
            <div class="card-header" style="background-color:#1e3f5a;color:white">
                <h3 class="card-title">Search and Tag</h3>
            </div>
            <div class="card-body">
 
                <div class="col-md-12">
                    <div class="input-group">
                        <select id="searchOptions" name="searchOptions" style="background-color: #1e3f5a; color: white; width: 140px; height: 45px">
                            <option selected value="1">Poi</option>
                            <option selected value="1">Vessel</option>
                        </select>
 
 
                        @(Html.Kendo().MultiColumnComboBox()
                            .Name("tagItem")
                            .DataTextField("name")
                            .DataValueField("Id")
                            .Filter("contains")
                            .FilterFields(new string[] { "name", "ContactTitle", "CompanyName", "Country" })
                            .Columns(columns =>
                            {
                                columns.Add().Field("name").Title("Contact Name").Width("200px");
                                columns.Add().Field("dob").Title("Date Of Brith").Width("200px");
 
                            })
                            .FooterTemplate("Total #: instance.dataSource.total() # items found")
                            .HtmlAttributes(new { style = "width:80%;" })
                            .Height(400)
                            .DataSource(source => source
                                .Custom()
                                .Transport(transport => transport
                                    .Read(read =>
                                    {
                                        read.Action("SearchQuery", "MISObjects")
                                            .Data("onAdditionalData");
                                    }))
                            )
                            )
                        <button class="btn-primary" value="Link To Case" style=" background-color:#1e3f5a;color:white">Link To Case</button>
 
                    </div>
                    
                    <script>
                        function onAdditionalData() {
                            return {
                                text: $("#customers").val()
                            };
                        }
                    </script>
  public IActionResult LinkToCase(int tagItem, string sesearchOptionsr) {
            Int32.TryParse(TempData.Peek("CaseId").ToString(), out int resultCaseId);
 
            POI newPoi = new POI();
            newPoi =  _context.Pois.SingleOrDefault(w => w.Id == tagItem);
 
            newPoi.MISObjectId = resultCaseId;
 
            _context.Pois.Add(newPoi);
 
            _toast.AddSuccessToastMessage(
                $"You have linked {newPoi.FirstName} {newPoi.LastName} to case {resultCaseId:d8}");
 
            return RedirectToAction("Edit", new { id = resultCaseId });
}

 

7 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 20 Aug 2020, 12:24 PM

Hello David,

I tested the scenario and did not come across any issues with regard to accessing the selected item's id in the LinkToCase action through the tagItem parameter, see the attached screenshot.

I am also attaching a sample project I used to check the behavior in. I've made some small modifications to the MultiColumnComboBox you posted - changed the "name" and "dob" fields to start with capital letters, to match the fields in the model, and also fixed fixed the name of the other parameter in the LinkToCase  action - from "sesearchOptionsr" to "searchOptions". Also the name of the controller in the example is Home instead of MISObjects.

I hope the example would help you identify the issue in your logic.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
David
Top achievements
Rank 1
answered on 20 Aug 2020, 03:33 PM
Thats odd I will have a look at sample now I am using .net core 3.1 weather or not that makes a difference thanks for providing a sample
0
David
Top achievements
Rank 1
answered on 20 Aug 2020, 03:34 PM
In mine they to be lower case for some reason or the json will not be found.
0
David
Top achievements
Rank 1
answered on 20 Aug 2020, 03:49 PM

Found my issue it was down to this. Being missing every new project i keep forgetting about it and it comes back to bite me in the ass lol thanks.

.AddNewtonsoftJson(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());


 

[quote]

Ivan Danchev said:

Hello David,

I tested the scenario and did not come across any issues with regard to accessing the selected item's id in the LinkToCase action through the tagItem parameter, see the attached screenshot.

I am also attaching a sample project I used to check the behavior in. I've made some small modifications to the MultiColumnComboBox you posted - changed the "name" and "dob" fields to start with capital letters, to match the fields in the model, and also fixed fixed the name of the other parameter in the LinkToCase  action - from "sesearchOptionsr" to "searchOptions". Also the name of the controller in the example is Home instead of MISObjects.

I hope the example would help you identify the issue in your logic.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

[/quote]
0
David
Top achievements
Rank 1
answered on 20 Aug 2020, 03:51 PM
It might be worth adding that in the install guide it has been a bug bare in me for a long time since your components require it to be normal case and not pascal case
0
David
Top achievements
Rank 1
answered on 20 Aug 2020, 04:17 PM

I also have a column called which i would like to capture but again same issue comming blank

  columns.Add().Field("SearchType").Title("Type").Width("200px");
                                

 

[quote]Ivan Danchev said:

Hello David,

I tested the scenario and did not come across any issues with regard to accessing the selected item's id in the LinkToCase action through the tagItem parameter, see the attached screenshot.

I am also attaching a sample project I used to check the behavior in. I've made some small modifications to the MultiColumnComboBox you posted - changed the "name" and "dob" fields to start with capital letters, to match the fields in the model, and also fixed fixed the name of the other parameter in the LinkToCase  action - from "sesearchOptionsr" to "searchOptions". Also the name of the controller in the example is Home instead of MISObjects.

I hope the example would help you identify the issue in your logic.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

[/quote]
0
Ivan Danchev
Telerik team
answered on 20 Aug 2020, 04:34 PM

David,

I'm glad you've found the issue to be related to JSON serialization and made the necessary changes to the project's configuration.

We have covered the configuration needed for maintaining the casing of the properties in the JSON Serialization documentation section: https://docs.telerik.com/aspnet-core/compatibility/json-serialization#overview

As for the issue you are having with a column value not being sent to the controller, the MultiColumnComboBox sends only its DataValueField value ("Id" in this case). If you want to send any other field value you should do it through other means. For example saving the column value with js in a hidden field nested in the form and then accessing that value in the action after the form is submitted.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MultiColumnComboBox
Asked by
David
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
David
Top achievements
Rank 1
Share this question
or