Sneha K

Sneha K

  • 1.1k
  • 527
  • 190k

show div based on Dropdown selection in mvc4?

Jan 30 2016 12:47 AM

Hi my j query code is not working.
My View 
 
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.POVisit, new { @class = "control- label",id="POVisit" })
@Html.DropDownList("POVisitID", "Select")
</div>
</div>
<div id ="OrderReceivedYesNo">
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.OrderReceived, new { @class = "control-label" })
@Html.RadioButton("OrderReceived", 1) Yes
@Html.RadioButton("OrderReceived", 0) No
</div>
</div>
</div>
 
My jquery code 
 
 
$(document).ready(function () {
$("#OrderReceivedYesNo").hide();
});
$(document).ready(function () {
$("#POVisit").on('change', function () {
if (this.value == "Order")
{
$("#OrderReceivedYesNo").show();
}
});
});
 

The above code is not working. The POVisit Dropdown have 7 values which is directly fetch from Database. Initially i hide the OrderReceived radio buttons. If i select the "Order" value in POVisit DropDown it needs to show the "OrderReceivedYesNo" div. But the above code that show code is not working.

And my DateTimePicker is also not working.

<script src="~/Scripts/jquery-1.9.1.js"></script>
<link rel="stylesheet"href="//code.jquery.com/ui/1.11.4/themes/smoothness/
jquery-ui.css">
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="~/plugins/jQuery/jQuery-2.1.4.min.js"></script>
$(document).ready(function () {
$("#Date").datepicker({
maxDate: "+0D",
changeMonth: true,
changeYear: true,
yearRange: "-100:+0",
dateFormat: "M/dd/yy",
});
})
<div class="col-sm-4">
<div class="form-group">
@Html.LabelFor(model => model.Date , new { @class = "control-label" })
@* @Html.TextBoxFor(model => model.Date, new { @class = "form-control", type = "text", id="Date" })*@
<input type="text" id="Date" class = "form-control date" />
<span class="error">Valid order date required (ex. MM-dd-yyyy)</span>
</div>
</div>
</div>

it shows the "Date" format in view but if i select the date and trying to save the date in Db it doesn't save the date in DB .The date column is null and value is null. please any one give me the suggestion and solution to my problem..

Advance Thanks

 
 
 
 
 
 

Answers (7)