This code is in my Index View.
<pre><tr>
<td class="Label">
@Html.Label("*DropDown")
</td>
<td>
@Html.DropDownList("DropDown",
new List<SelectListItem>
{ new SelectListItem {Text = "Tina", Value="1"},
new SelectListItem {Text = "Mina", Value="2"},
new SelectListItem {Text = "Jina", Value="3"},
new SelectListItem {Text = "Pina", Value="4"},
}, "Select one", new { @class = "ddl", })
</td>
</tr>
<tr>
<td class="Label">
@Html.LabelFor(m => m.PPC)
</td>
<td>
@Html.Hidden("PPC", null, new { id = "ppc1"})
@Html.Label("PPC", new { id = "ppc" })
</td>
</tr>
basically i want to populate my label and hidden field on selection of the DropDown automatically.
And to populate my Label and hidden field i am using this jquery.
$(document).ready(function () {
$('#DropDown').change(function () {
var valueOfDDl = $("#DropDown option:selected").text();
if (valueOfDDl == 'Tina') {
$("#ppc").text("1 MW");
$("#ppc1").text("1 MW");
}
else if (valueOfDDl == 'Mina') {
$("#ppc").text("1.5 MW");
$("#ppc1").text("1.5 MW");
}
else if (valueOfDDl == 'Jina') {
$("#ppc1").text("2 MW");
$("#ppc").text("2 MW");
}
else if (valueOfDDl == 'Pina') {
$("#ppc").text("2.5 MW");
$("#ppc1").text("2.5 MW");
}
})
I am successfuly setting the value
but when i tried to access that value in controller xyz it is null
I have tried Request.Form["PPC"].Tostring();
i have even passed it to my controller like this
public ActionMethod xyz(string PPC)
{
Viewbag.ppc = ppc;
}
I have do have a ppc field in my model so i also tried
Viewbag.ppc = model.PPC;
But nothing seems to work.
*
One more thing i want the label to be empty but when i load my page it shows PPC as default value and if i put simple Html label validations is not working.