如何使用mvc在同一页面中添加和查看

时间:2017-10-26 13:24:34

标签: c# asp.net asp.net-mvc asp.net-mvc-4 model-view-controller

点击按钮,我们将医生的经验保存到数据库中。保存后我需要使用foreach条件在同一页面查看医生体验详细信息。在我的代码中foreach代码不起作用。

library(dplyr)
mtcars %>% 
  group_by(cyl, am) %>% 
  summarise(mean = mean(mpg),
            quantile_10 = quantile(mpg, 0.1),
            quantile_90 = quantile(mpg, 0.9))
# A tibble: 6 x 5
# Groups:   cyl [?]
    cyl    am     mean quantile_10 quantile_90
  <dbl> <dbl>    <dbl>       <dbl>       <dbl>
1     4     0 22.90000       21.76       24.08
2     4     1 28.07500       22.38       32.85
3     6     0 19.12500       17.89       20.74
4     6     1 20.56667       19.96       21.00
5     8     0 15.05000       10.69       18.56
6     8     1 15.40000       15.08       15.72

弹出

 @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;
    }

2 个答案:

答案 0 :(得分:0)

如果您想查看单一医生的体验详情,您需要返回同一页面上的医生详细信息并根据查看详细信息准备视图。否则,如果您想在提交数据后查看医生详细信息列表,则需要返回同一视图的医生详细信息列表,并根据视图列表准备视图。

答案 1 :(得分:0)

当您单击提交按钮时,请求发送给AddExperience Action和Controllar Doctor您需要获取相同的Id数据并将视图传递给对象示例

IFS=. read -r major minor fix <<EOF
$version
EOF