如何使用mvc从表单中查看表中的数据

时间:2017-11-28 09:06:28

标签: javascript asp.net-mvc asp.net-mvc-4

在表单中输入所有详细信息后。当我点击进入总药品领域。所有字段应显示在下表中,然后我在表单中输入第二个详细信息的详细信息,然后所有字段数据应显示在第二行,就像我需要填写表格。最后我点击保存按钮它应该保存所有数据库中的表数据。我在网上搜索但我没有得到任何参考代码。

 @using (Html.BeginForm("PrescriptionManagement", "Prescription", FormMethod.Post, new { id = "myForm" }))
        {
            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)
            <section class="card">
                <div class="card-block">
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Prescription Date</label>
                                <div class='input-group date'>
                                    <input id="PrescriptionDate" name="PrescriptionDate" type="text" value=@DateTime.Now.ToString("dd/MM/yyyy") class="form-control" style="border-width: 0 0 2px 0;">
                                    <span class="input-group-addon">
                                        <i class="font-icon font-icon-calend"></i>
                                    </span>
                                    @Html.ValidationMessageFor(model => Model.prescriptionmanagement.PrescriptionDate, null, new { @style = "color: red" })
                                </div>
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Doctor Name</label>
                                @Html.DropDownList("DoctorID", null, "--- Select Doctor Name ---", new { @class = "select2-arrow" })
                                @Html.ValidationMessageFor(model => Model.prescriptionmanagement.DoctorID, null, new { @style = "color: red" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Patient Name</label>
                                @Html.DropDownList("PatientID", null, "--- Select Doctor Name ---", new { @class = "select2-arrow" })
                                @Html.ValidationMessageFor(model => Model.prescriptionmanagement.PatientID, null, new { @style = "color: red" })
                            </fieldset>
                        </div>
                    </div><br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Age</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Age, new { @class = "form-control", @id = "txtAge", placeholder = "Age" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Diagnosis</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Diagnosis, new { @class = "form-control", @id = "txtDiagnosis", placeholder = "Diagnosis" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Gender</label>
                                <br />
                                <div class="form-group form-group-radios">
                                    <div class="radio">
                                        @Html.RadioButtonFor(model => model.prescriptionmanagement.Gender, "Male", new { @name = "optionsRadios", @class = "form-control", @id = "radio-1" })
                                        <label for="radio-1">Male </label>
                                        &nbsp; &nbsp;&nbsp; &nbsp;
                                        @Html.RadioButtonFor(model => model.prescriptionmanagement.Gender, "Female", new { @name = "optionsRadios", @class = "form-control", @id = "radio-2" })
                                        <label for="radio-2">Female</label>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Weight</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Weight, new { @class = "form-control", @id = "txtWeight", placeholder = "Weight" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Temperature</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Temperature, new { @class = "form-control", @id = "txtTemperature", placeholder = "Temperature" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Blood Sugar</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.BloodSugar, new { @class = "form-control", @id = "txtBloodSugar", placeholder = "BloodSugar" })
                            </fieldset>
                        </div>
                    </div>
                    <br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Blood Pressure</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.BloodPressure, new { @class = "form-control", @id = "txtBloodPressure", placeholder = "BloodPressure" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">MedicineName</label>
                                @*@Html.TextBoxFor(model => Model.MedicineName, new { @class = "form-control", @id = "txtMedicineName", placeholder = "MedicineName" })*@
                                <div class="typeahead-container">
                                    <div class="typeahead-field">
                                        <span class="typeahead-query">
                                            @Html.TextBoxFor(model => Model.prescriptionmanagement.MedicineName, new { @class = "form-control", @id = "txtMedicineName", placeholder = "Medicine Name", name = "d", type = "search", autocomplete = "off" })
                                            <input type="hidden" id="hfCustomer" name="CustomerId" />
                                        </span>
                                    </div>
                                </div>
                                @Html.ValidationMessageFor(model => Model.prescriptionmanagement.MedicineName, null, new { @style = "color: red" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Drug Specifications</label>
                                <div class="tbl-cell tbl-cell-action button">
                                    <a href="#" data-toggle="modal" id="btnClick" data-target="#upload3Modal" class="btn btn-rounded btn-block">Drug Specifications&nbsp;&nbsp;<span class="font-icon-search"></span></a>
                                </div>
                            </fieldset>
                        </div>
                    </div><br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Days</label>
                                <input id="demo3" type="text" value="1" name="demo3" />
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Morning</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Morning, new { @Value = "0", @class = "form-control", @id = "txtMorning", placeholder = "Morning" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Afternoon</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Afternoon, new { @Value = "0", @class = "form-control", @id = "txtAfternoon", placeholder = "Morning" })
                            </fieldset>
                        </div>
                    </div><br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Evening</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Evening, new { @Value = "0", @class = "form-control", @id = "txtEvening", placeholder = "Morning" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Night</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Night, new { @Value = "0", @class = "form-control", @id = "txtNight", placeholder = "Morning" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">BF / AF</label>
                                <select class="select2-arrow" id="BFAF" name="Status">
                                    <option>--- Select BF / AF ---</option>
                                    <option value="AF">AF</option>
                                    <option value="BF">BF</option>
                                </select>
                            </fieldset>
                        </div>
                    </div><br />
                    <div class="row">
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">Dose / Ml</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.Dose, new { @Value = "0", @class = "form-control", @id = "txtDoseMl", placeholder = "Dose / Ml" })
                            </fieldset>
                        </div>
                        <div class="col-lg-4">
                            <fieldset class="form-group">
                                <label class="form-label" for="exampleInput">TotalMedications</label>
                                @Html.TextBoxFor(model => Model.prescriptionmanagement.TotalMedications, new { @class = "form-control", @id = "txtTotalMedications", placeholder = "Total Medications" })
                                @Html.ValidationMessageFor(model => Model.prescriptionmanagement.TotalMedications, null, new { @style = "color: red" })
                             </fieldset>
                        </div>
                    </div>
                    <input type="submit" name="actionType" value="Save" class="btn btn-rounded btn-inline btn-success" />
                    <br /><br />
                    <span class="label label-success">@ViewBag.Message</span>
                </div>
            </section>
            <!-- Start Model Pop Up-->
            <div class="modal fade" id="upload3Modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <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">Drug Specifications</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">
                                            <br />
                                            <div class="row">
                                                <div class="col-lg-4">
                                                    <fieldset class="form-group">
                                                        <label class="form-label" for="exampleInput">Generic Name</label>
                                                        @Html.TextBoxFor(model => Model.productmaster.GenericName, new { @class = "form-control", @id = "txtGenericName", placeholder = "Generic Name" })
                                                        @*@Html.Hidden("GenericID", null, new { @id = "hdnGenericID" })*@
                                                        <input type="hidden" id="hdnGenericID" name="GenericID" />
                                                    </fieldset>
                                                </div>
                                            </div>
                                        </div><!--.tab-pane-->
                                    </div><!--.tab-content-->
                                </div><!--.modal-upload-cont-in-->
                            </div><!--.modal-upload-cont-->
                        </div>
                    </div>
                </div>
            </div><!--.modal-->
            <!-- End Model Pop Up-->
        }

view

参考图片:

e

1 个答案:

答案 0 :(得分:2)

很抱歉,如果我的回答是通用的,但我对您的具体案例了解不多

客户端脚本

<script>
    function UpdateForm(arg) {
      $.ajax({
        url: '@Url.Action("yourMethod", "yourController")',
        type: "GET",
        data: { arg1: arg1 },
        success: (function (result) {
        $("#yourDiv").html(result);
      });
    }
</script>

主视图

<div id="yourDiv">
  @Html.Partial("~/Views/yourController/yourPartialView.cshtml", yourModel)
</div>

<强> PartialView

@model yourNamespace.yourViewModel
<form>
  @Html.EditorFor(model => model)
  <div>
    <fieldset>
        <legend>A legend</legend>
        @Html.CheckBoxFor(model => model.field1)
        @Html.EditorFor(model => model.field2, new { htmlAttributes = new { @class = "form-control" } })
            <!-- etc... -->
    </fieldset>
  </div>
</form>

控制器

public class yourController : Controller
{
    public ActionResult yourMethod(object arg1)
    {
        //Get data from database here
        return PartialView("yourView", yourModel);
    }
}

Reference

编辑:

没有Ajax

<script>
  $('#yourDiv').load('@Url.Action("yourMethod", "yourController")', { arg1 : arg1 });
</script>