Autocomplete - Model not updated

3 posts, 0 answers
  1. Nervia
    Nervia avatar
    4 posts
    Member since:
    Nov 2007

    Posted 29 Jul 2013 Link to this post


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

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

    Someone can
    help me?

    @(Html.Kendo().AutoCompleteFor(model => model.CountryCode)
                        .DataSource(ds =>
                            ds.Read(read =>
                                read.Action("GetCountriesForAutoComplete", "Country")
            function onAdditionalData() {
                return {
                    text: $("#acCountry").val()
    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:
            public JsonResult Create(Region region)
            {//region.CountryCode is null!!!!
                JsonResult jsonOutput = null;
                if (ModelState.IsValid)
                        ConvertToUpperCase(region.GetType(), region);
                        jsonOutput = Json(new { success = true });
                    catch (Exception ex)
                        jsonOutput = ErrorJson(ex);
                    jsonOutput = ErrorJson(ModelState);
                return jsonOutput;
  2. Nervia
    Nervia avatar
    4 posts
    Member since:
    Nov 2007

    Posted 30 Jul 2013 Link to this post

    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"
  3. Petur Subev
    Petur Subev avatar
    1882 posts

    Posted 31 Jul 2013 Link to this post

    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")

    Petur Subev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top