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:
Autocomplete Read:
Create Method:
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
>
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);
}
[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;
}