working in mvc
In this Json result i am loading some dropdownlist it is working fine..in that if i select some value description value should be displayed in the textbox….here ViewData[“Description”] = AttributesLibrary.Description; in this i am getting description values but i cant able to display it……
public JsonResult PopulateGradeScaleSetUp(string trackId)
{
List<GradeDivisionValues> GradeDivisionValuesList = new List<GradeDivisionValues>();
SelectList fieldIds = new SelectList(new List<Gradescale> { });
AttributesLibrary AttributesLibrary = new AttributesLibrary();
try
{
if (!string.IsNullOrEmpty(trackId))
{
string gradescaleID;
Context.SetPrivilegeContext(GrowthDataConstant.ViewAttributeLibrary);
AttributesLibrary = GrowthMasterDataProxy.GetAttributeByAttributeId(trackId);
gradescaleID = AttributesLibrary.AttributePropertyDetails.GradeScaleDetails.Identifier;
Context.SetPrivilegeContext(GrowthDataConstant.ViewGradeScale);
Gradescale gradeScale = new Gradescale();
gradeScale = GrowthMasterDataProxy.GetGradeScaleById(gradescaleID);
Dictionary<string, GradeDivisionValues> GradeDivisionValuesDic = gradeScale.GradeDivisionValues;
if (GradeDivisionValuesDic != null && GradeDivisionValuesDic.Count > 0)
{
GradeDivisionValuesList = GradeDivisionValuesDic.Values.ToList();
}
fieldIds = new SelectList((IEnumerable)GradeDivisionValuesList, "NumericalValue", "TextValue");
ViewData["Description"] = AttributesLibrary.Description;
}
return Json(fieldIds, JsonRequestBehavior.AllowGet);
}
catch (ArgumentException argumentException)
{
ExceptionService.HandleException(argumentException, _defaultPolicy);
return Json("Error", JsonRequestBehavior.AllowGet);
}
}
This is my view:
<%= Html.TextBox("Description", (string)ViewData["Description"])%>
Your controller action returns JSON which makes me to believe that you are invoking it using AJAX. In order to update the value of the textbox you need to include it in the JSON result instead of using
ViewData. For example:Now all that’s left is to use this value in your AJAX success handler. Supposing you are using jquery it might look like this:
and the textbox definition simply: