I have a dropdown box in an MVC 4 view. When the value in the dropdown box changes I want to read all of the values selected. Each Selection contains 3 items. First: Id, Second: the value the user sees on the form and third: is a path to a file. Everything works fine but I cant read the TemplatePath. How do I use jquery to read the templatePath selected by the user.
I know how to read the id and the selected value, but I cant seem to find a way to read the path.
My controller creates a SelectList used in the view:
ViewBag.TemplateList = new SelectList(db.Templates.ToList(), "TemplateId", "TemplateTitle", "TemplatePath");
The view uses the select list and populates a dropdown box:
@Html.DropDownListFor(model => model.TemplateId, ViewBag.TemplateList as IEnumerable<SelectListItem>, "-- No Template --", new { @id = "TemplateChoice"})
I have a javascript file using Jquery so when the template dropdown box is changed, I want to read the TemplatePath from the dropdown box.
My javascript file is as follows:
$("document").ready(function () {
$("#TemplateChoice").change(function () {
var templateID = $("#TemplateChoice option:selected").val();
var templateText = $("#TemplateChoice option:selected").text();
//Here I need code that will read the TemplatePath
});
});
Any help would be appreciated.