C# 如何使用mvc在同一页面中添加和查看
单击按钮,我们将医生经验保存到数据库中。保存后,我需要使用foreach条件在同一页面中查看医生经验详细信息。在我的代码中,每个代码都不起作用C# 如何使用mvc在同一页面中添加和查看,c#,asp.net,asp.net-mvc,asp.net-mvc-4,model-view-controller,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Model View Controller,单击按钮,我们将医生经验保存到数据库中。保存后,我需要使用foreach条件在同一页面中查看医生经验详细信息。在我的代码中,每个代码都不起作用 @model MedeilMVC_CLOUD.Models.DoctorMainModel @using (Html.BeginForm("AddExperience", "Doctor", FormMethod.Post, new { id = "myForm", enctype = "multipart/form-data" }))
@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)
{
}
}
如果你想了解单身医生的体验详情,您需要返回到具有单个医生详细信息的同一页面,并根据视图详细信息准备视图。否则,如果您希望在提交数据后查看医生详细信息列表,则需要将医生详细信息列表返回到同一视图,并根据视图列表准备视图。当您单击“提交”按钮时,请求将发送到AddExperienceAction和Controllar Doctor您需要获得相同的Id数据,并将视图传递给对象示例
public ActionResult AddExperience(modal m)
{
//your code for save the current user data in database after add you need to
var get = new JobOrderRepository().FirstOrDefault(x => x.Id == m.id);
return View(get);
}
例如,任何参考代码都可用或编辑我的代码?@K Naga MalleshCan you show your controller?@Edward i edited code check it
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;
}
[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();
}
}
public ActionResult AddExperience(modal m)
{
//your code for save the current user data in database after add you need to
var get = new JobOrderRepository().FirstOrDefault(x => x.Id == m.id);
return View(get);
}