I am stuckup with little problem
I have the form contains 3 hidden controls, I am sending values through jquery. Upto this its working fine while I keep alert.
I am using FormCollection and try to retrieve those hidden values in .cs file but I am unable to retireve those values. When I keep break point on FormCollections its showing all the hidden control names including key numbers.
View:
<tr>
<td colspan ="2">
@Html.Hidden("hdnddlid")
@Html.Hidden("hdnrblMale")
@Html.Hidden("hdnrblFeMale")
</td>
</tr>
<script type="text/javascript">
$(document).ready(function () {
$("input[name='Gender']").change(function () {
if ($("input[name='Gender']:checked").val() == '1') {
hdnrblMale = "Male";
}
else if ($("input[name='Gender']:checked").val() == '0') {
hdnrblFeMale = "FeMale";
}
});
});
</script>
Code in .cs file
public static void InsertPersonalDetails(PersonalDetails modelPersonal, FormCollection frmHdnValues)
{
try
{
PersonalDbContext db = new PersonalDbContext();
string Male = frmHdnValues["hdnrblMale"].ToString();
string Female = frmHdnValues["hdnrblFeMale"].ToString();
db.Entry(modelPersonal).State = EntityState.Added;
//pDetails.Add(Objpd);
db.SaveChanges();
// return pDetails;
}
Thanks
Am I missing something or doesn’t your jQuery need to be:
instead of
also make sure that the fields are within a form being submitted.
I use a combination of
show up in fiddler – e.g. localhost.:69230 instead of
localhost:69230)
to debug this type of thing.. that way you should have visibility of all parts of the chain.