ボタンをクリックすると、医師の経験がデータベースに保存されます。保存した後、私はforeach条件を使用して同じページで医者の経験の詳細を表示する必要があります。私のコードでforeachコードが動作していません。mvcを使用して同じページに追加して表示する方法
@model MedeilMVC_CLOUD.Models.DoctorMainModel
@using (Html.BeginForm("AddExperience", "Doctor", FormMethod.Post, new { id = "myForm", enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<a href="#" data-toggle="modal" data-target="#upload3Modal" class="btn btn-rounded btn-block">Add Experience</a>
@foreach (MedeilMVC_CLOUD.Models.DoctorExperience doctor in Model.DoctorExp)
{
}
}
ポップアップ
<div class="modal fade" id="upload3Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content" style="height: 580px;">
<div class="modal-header">
<button type="button" class="modal-close" data-dismiss="modal" aria-label="Close">
<i class="font-icon-close-2"></i>
</button>
<h4 class="modal-title" id="myModalLabel">Add Experience</h4>
</div>
<div class="modal-upload menu-big-icons">
<div class="modal-upload-cont">
<div class="modal-upload-cont-in" style="border-left: none;">
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="tab-upload-3-1">
<label class="form-label semibold control-label">Hospital Name</label>
@Html.TextBoxFor(model => Model.doctorExperience.HospitalName, new { @class = "form-control", @id = "txtPHospitalName", placeholder = "Enter the Hospital Name" })
@Html.ValidationMessageFor(model => Model.doctorExperience.HospitalName, null, new { @style = "color: red" })
<br />
<label class="form-label semibold control-label">Department</label>
@Html.DropDownList("Department", null, "--- Select Department ---", new { @class = "select2-arrow" })
@Html.ValidationMessageFor(model => Model.doctorExperience.DepartmentID, null, new { @style = "color: red" })
<br /> <br />
<label class="form-label semibold control-label">From Date</label>
<div class='input-group date'>
<input id="txtPFromDate" type="text" value="24/10/1984" class="form-control">
<span class="input-group-addon">
<i class="font-icon font-icon-calend"></i>
</span>
</div>
<br />
<label class="form-label semibold control-label">To Date</label>
<div class='input-group date'>
<input id="txtPToDate" type="text" value="24/10/1984" class="form-control">
<span class="input-group-addon">
<i class="font-icon font-icon-calend"></i>
</span>
</div>
<br />
<label class="form-label semibold control-label">Work Description</label>
@Html.TextAreaFor(model => Model.doctorExperience.WorkDescription, new { @class = "form-control maxlength-simple", @id = "txtPWorkDescription", maxlength = "500", placeholder = "Max length 500 chars" })
<br />
<input type="submit" name="submit" id="btnsaveExperience" value="Save Experience" class=" btn btn-rounded btn-inline btn-success" />
</div><!--.tab-pane-->
</div><!--.tab-content-->
</div><!--.modal-upload-cont-in-->
</div><!--.modal-upload-cont-->
</div>
</div>
</div>
</div><!--.modal-->
クラス:
public class DoctorMainModel
{
public IEnumerable<DoctorExperience> DoctorExp { get; set; }
}
[Table("Doctorexperience")]
public class DoctorExperience
{
[Key]
public int ExperienceID { get; set; }
public int DoctorID { get; set; }
[Display(Name = "HospitalName")]
[Required(ErrorMessage = "Enter the Hospital Name")]
public string HospitalName { get; set; }
[Display(Name = "Department")]
[Required(ErrorMessage = "Enter the Department")]
public int DepartmentID { get; set; }
//[Display(Name = "Designation")]
//[Required(ErrorMessage = "Enter the Designation")]
//public string Designation { get; set; }
[Display(Name = "FromDate")]
[Required(ErrorMessage = "From Date")]
public DateTime FromDate { get; set; }
[Display(Name = "FromDate")]
[Required(ErrorMessage = "To Date")]
public DateTime ToDate { get; set; }
public string WorkDescription { get; set; }
public int CreatedBy = -1;
public DateTime CreatedDate = DateTime.UtcNow;
public int ModifiedBy = -1;
public DateTime ModifiedDate = DateTime.UtcNow;
}
コントローラ:uは、単一の医師の経験の詳細を確認したい場合は
[HttpPost]
public ActionResult AddDoctorExperience(DoctorMainModel mainModel)
{
try
{
int docId = Convert.ToInt32(Session["docID"]);
if (ModelState.IsValid && docId > 0)
{
DoctorReg obj = new DoctorReg();
int id = obj.AddDoctorExperience(mainModel, docId);
if (id != 0)
{
Session["experienceID"] = id.ToString();
ViewBag.Message = "Experience added successfully";
return Json(new { id = Session["experienceID"] });
}
return View();
}
return View();
}
catch
{
return View();
}
}
をobjectにビューを渡す必要がhttp://www.c-sharpcorner.com送信ボタンをクリックしてください/ UploadFile/ff2f08 /複数のモデルを1つのビューで表示するmvc/ –
コントローラを表示できますか? –
@Edward私はコードを編集しました –