1
Answer

How to pass the value for Show/hide in Edit mode MC5?

Hi i want to know how to pass the value to show and hide div fields in Update mode.
I have one field called purpose of visit (dropdown) in my view. If i select the Purpose of visit as Order means the OrderReceived div will be visible other wise it will be in hide mode.
My Model ViewModel
public System.Guid POVisitID { get; set; }
public string POVisit { get; set; }
public bool OrderReceived { get; set; }
My View code
<div class="col-sm-3">
<div class="form-group">
<span style="color: #f00">*</span>
@Html.Label("Purpose of Visit", new { @class = "control-label", styles = "font-family: Arial;" })
@Html.DropDownList("POVisitID", null, "Select", new { @class = "form-control required" })
</div>
</div>
<div id="OrderReceived">
<div class="col-sm-3">
<div class="form-group">
@Html.Label("Order Received", new { @class = "control-label" })
<label>
@Html.RadioButtonFor(model => model.OrderReceived, "true", new { id = "" }) Yes
</label>
<label>
@Html.RadioButtonFor(model => model.OrderReceived, "false", new { id = "" }) No
</label>
</div>
</div>
</div>
My Jquery code
$(document).ready(function () {
$('#OrderReceived').hide()
$('#OrderReceivedNoDetails').hide();
$("#POVisitID").change(function () {
if ($("#POVisitID option:selected").text() == "Order") {
$("#OrderReceived").show();
}
else {
$("#OrderReceived").hide();
$('#OrderReceivedNoDetails').hide();
}
});
});
My Controller
public ActionResult Create(VisitorsViewModel visitorviewmodel)
{
ViewBag.POVisitID = new SelectList(db.POVisits, "POVisitID", "POVisit1", visitorviewmodel.POVisitID);
if (visitorviewmodel.OrderReceived == true)
visitorviewmodel.OrderReceived = true;
else
visitorviewmodel.OrderReceived = false;
var VisitorsViewObj = new VisitorsForm()
{
POVisitID = visitorviewmodel.POVisitID,
OrderReceived = Convert.ToBoolean(visitorviewmodel.OrderReceived),
};
db.VisitorsForms.Add(VisitorsViewObj);
db.SaveChanges();
ModelState.Clear();
return View();
}
Now what i want is how i pass the value for show and hide field in update mode. Suppose if i put one entry by selecting Purpose of visit as 'Order' and select OrderReceived and saved it in db. Now i like to change the Purpose of Visit as Complaints. So i click the Edit button means It have to pass the value to dropdown and also show and hide div. I passed the value to dropdown in edit mode. but i cant able to show the div once i clcik the edit button. I tried my level best to explain the issue . Anyone understand my issue and help me to resolve this problem
My Edit Code
Controller Code
public ActionResult Edit(Guid ?id)
{
WafeERP_NEWEntities db = new WafeERP_NEWEntities();
VisitorsViewModel objvisitorsviewmodel = new VisitorsViewModel();
View_VisitorsForm objviewvisitorsForm = db.View_VisitorsForm.Find(id);
if (objviewvisitorsForm.OrderReceived== true)
{
objvisitorsviewmodel.OrderReceived = true;
}
else
{
objvisitorsviewmodel.OrderReceived = false;
}
ViewBag.POVisitID = new SelectList(db.POVisits, "POVisitID", "POVisit1", objviewvisitorsForm.POVisitID);
return View(objvisitorsviewmodel);
}
My View Code
<div class="col-sm-3">
<div class="form-group">
<span style="color: #f00">*</span>
@Html.Label("Purpose of Visit", new { @class = "control-label", styles = "font-family: Arial;" })
@Html.DropDownList("POVisitID", null, "Select", new { @class = "form-control required" })
</div>
</div>
<div id="OrderReceived">
<div class="col-sm-3">
<div class="form-group">
@Html.Label("Order Received", new { @class = "control-label" })
<label>
@Html.RadioButtonFor(model => model.OrderReceived, "true", new { id = "" }) Yes
</label>
<label>
@Html.RadioButtonFor(model => model.OrderReceived, "false", new { id = "" }) No
</label>
</div>
</div>
</div>
Advance Thanks..

Answers (1)