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

Autocomplete - Model not updated

2 Answers 291 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Nervia Consultores S.L.
Top achievements
Rank 1
Nervia Consultores S.L. asked on 29 Jul 2013, 04:11 PM
Hello
Comunity:

It’s the
first time that I use the “AutoCompleteFor” of Kendo MVC Razor.

The
“AutoCompleteFor” works correctly but when I call to Create Function, the Model
not recognized the selected value in the AutoComplete.

Someone can
help me?

AutoComplete:
@(Html.Kendo().AutoCompleteFor(model => model.CountryCode)
                    .Name("acCountry")
                    .DataTextField("ISO")
                    .DataSource(ds =>
                    {
                        ds.Read(read =>
                        {
                            read.Action("GetCountriesForAutoComplete", "Country")
                                .Data("onAdditionalData");
                        })
                        .ServerFiltering(true);
                    })
                )
 
<script>
        $.validator.unobtrusive.parse("#CreateRegionForm");
        //$('#CreateRegionForm').kendoValidator();
        function onAdditionalData() {
            return {
                text: $("#acCountry").val()
            };
        }
         
    </script>
Autocomplete Read:
public ActionResult GetCountriesForAutoComplete(string text)
        {
            text = text.ToUpper();
            var result = FwdManager.Country.GetAll()
                .Where(p => p.ISO.Contains(text) || p.NameEsp.Contains(text))
                .Select(s => new DtoCountry()
                                            {
                                                Id = s.Id,
                                                ISO = s.ISO,
                                                NameEsp = s.NameEsp,
                                                NameEng = s.NameEng,
                                                Observations = s.Observations,
                                                PAIS_UNION_EUROPEA = s.PAIS_UNION_EUROPEA,
                                                Active = s.Active
                                            });
 
            return Json(result, JsonRequestBehavior.AllowGet);
        }
Create Method:
[HttpPost]
        public JsonResult Create(Region region)
        {//region.CountryCode is null!!!!
            JsonResult jsonOutput = null;
            if (ModelState.IsValid)
            {
                try
                {
                    ConvertToUpperCase(region.GetType(), region);
                    CheckKeyFields(region);
                    FwdManager.Region.Insert(region);
                    FwdManager.Commit();
                    jsonOutput = Json(new { success = true });
                }
                catch (Exception ex)
                {
                    jsonOutput = ErrorJson(ex);
                }
            }
            else
            {
                jsonOutput = ErrorJson(ModelState);
            }
            return jsonOutput;
        }

2 Answers, 1 is accepted

Sort by
0
Nervia Consultores S.L.
Top achievements
Rank 1
answered on 30 Jul 2013, 07:32 AM
I do not know if you understand me.My question is how I can run the "AutoComplete" in the POST method and the "CountryCode" the object already filled when the receiver.
I know how to receive it with the action "Request.Params" but I think the most "correct"
0
Petur Subev
Telerik team
answered on 31 Jul 2013, 01:34 PM
Hello Roberto,

Either remove the .Name("acCountry")  (so it will be automatically generated to be the same as the name of the property) that you specified or name it the same way as the name of the property .Name("CountryCode")

Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
AutoComplete
Asked by
Nervia Consultores S.L.
Top achievements
Rank 1
Answers by
Nervia Consultores S.L.
Top achievements
Rank 1
Petur Subev
Telerik team
Share this question
or