Couple of links I've tried, that led me to my code... which isn't working :D
Get The Drop on DropDownLists and Creating Cascading Dropdown Lists
I am trying to allow the user to select a part number (itemnmbr) from a dropdown list and upon their selection, have the page refresh the part description (itemdesc) textbox with the correct value. Below is the closest I've gotten.
VIEW CODE:
<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#ITEMNMBR").change(function () {
$.get("/PartsLabor/GetPartDesc", $(this).val(), function (data) {
$("#ITEMDESC").val(data);
});
});
});
</script>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>Add part to call: @ViewBag.CALLNBR</legend>
@Html.LabelFor(model => model.ITEMNMBR, "Item Number")
@Html.DropDownList("ITEMNMBR", (SelectList) ViewBag.Items, "Please Select a Part #")
@Html.ValidationMessageFor(model => model.ITEMNMBR)
<br />
@Html.LabelFor(model => model.ITEMDESC, "Description")
@Html.EditorFor(model => model.ITEMDESC)
@Html.ValidationMessageFor(model => model.ITEMDESC)
<br />
<input type="submit" class="submit" value="Add Part" />
</fieldset>
}
Controller Code:
[Authorize]
public ActionResult PCreate(string call)
{
var q = db.IV00101.Select(i => new { i.ITEMNMBR});
ViewBag.Items = new SelectList(q.AsEnumerable(), "ITEMNMBR", "ITEMNMBR");
ViewBag.CALLNBR = call;
return View();
}
public ActionResult GetPartDesc(char itemnmbr)
{
var iv101 = db.IV00101.FirstOrDefault(i => i.ITEMNMBR.Contains(itemnmbr));
string desc = iv101.ITEMDESC;
return Content(desc);
}
Firefox Error Console returns:
Timestamp: 12/28/2012 2:40:29 PM Warning: Use of attributes' specified attribute is deprecated. It always returns true. Source File: http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.6.4.min.js Line: 2
Timestamp: 12/28/2012 2:40:34 PM Warning: Use of getAttributeNode() is deprecated. Use getAttribute() instead. Source File: ~/Scripts/jquery-1.6.4.min.js Line: 3
Firefox Web Console returns those two, as well as the below (which lands between the above two):
Request URL: ~/PartsLabor/GetPartDesc?002N02337 Request Method: GET Status Code: HTTP/1.1 500 Internal Server Error