Asp.net mvc 5 在Dropdownlist EF6之外保存一个值

Asp.net mvc 5 在Dropdownlist EF6之外保存一个值,asp.net-mvc-5,entity-framework-6,Asp.net Mvc 5,Entity Framework 6,我希望保存一个名为AssetSignmentId的id字段,每次保存新模型名时,该字段的值为“2” 我想看看我是否能做到以下几点: 如果Modelname不为null,则将Modelname和AssetAssignmentID保存到=“2” 然而,它抱怨非静态字段需要对象引用。 如果在ClinicalAsset模型中引用AssetSignmentId,则无法将int类型转换为Model 填充的下拉列表 private void PopulateModelDropDownList(object s

我希望保存一个名为AssetSignmentId的id字段,每次保存新模型名时,该字段的值为“2”

我想看看我是否能做到以下几点:

如果Modelname不为null,则将Modelname和AssetAssignmentID保存到=“2”

然而,它抱怨非静态字段需要对象引用。 如果在ClinicalAsset模型中引用AssetSignmentId,则无法将int类型转换为Model

填充的下拉列表

private void PopulateModelDropDownList(object selectedModel = null)
        {
            var ModelsQuery = from d in db.Models.Where(x => x.AssetAssignmentID == 2) orderby d.ModelName select d;
            ViewBag.ModelDropDown = new SelectList(ModelsQuery, "ModelID", "ModelName", selectedModel);
        }
我希望每次向数据库提交新的ModelName时,AssetAssignmentID总是等于2的值

编辑

private void PopulateModelDropDownList(object selectedModel = null)
        {
            var ModelsQuery = from d in db.Models.Where(x => x.AssetAssignmentID == 2) orderby d.ModelName select d;
            ViewBag.ModelDropDown = new SelectList(ModelsQuery, "ModelID", "ModelName", selectedModel);
        }
我也试过了


                      var clinicalAsset = new ClinicalAsset { AssetAssignmentID = 2 };

                    if (clinicalAssets.ModelName != null)
                    {
                        clinicalAssets.ModelName = clinicalAssets.ModelName;

                    }


                    db.ClinicalAssets.Add(clinicalAsset);
                    db.SaveChanges();
                    return RedirectToAction("Details", "ClinicalAssets", new { ClinicalAssetID = clinicalAssets.ClinicalAssetID });

但错误是:无法将类型“int”隐式转换为“Assets.Models.Model”

设置型号:

using Assets.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Assets.Areas.Clinical.Models
{
    public class ClinicalAsset
    {

        [Key]
        public int ClinicalAssetID { get; set; }
        public int AssetTypeID { get; set; }
        public int? ProductID { get; set; }
        public int? ManufacturerID { get; set; }
        public int? ModelID{ get; set; }
        public int? SupplierID { get; set; }
        [StringLength(100, MinimumLength = 2)]
        public string SerialNo { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd/MM/yy}", ApplyFormatInEditMode = true)]
        public DateTime? PurchaseDate { get; set; }
        [StringLength(100, MinimumLength = 2)]
        public string PoNo { get; set; }
        [DisplayFormat(DataFormatString = "{0:c2}", ApplyFormatInEditMode = true)]
        public decimal? Costing { get; set; }
        public int? TeamID { get; set; }
        public int? BudgetCodeID { get; set; }
        public int? StaffID { get; set; }
        public bool? Filter { get; set; }



        public virtual Model ModelName { get; set; }
        public virtual Model AssetAssignmentID { get; set; }
        public virtual BudgetCode BudgetCodeJoinColumn { get; set; }
        public virtual Product ProductName { get; set; }
        public virtual AssetType AssetTypeName { get; set; }
        public virtual Manufacturer ManufacturerName { get; set; }
        public virtual Staff StaffName { get; set; }
        public virtual Team TeamName { get; set; }
        public virtual Supplier SupplierName { get; set; }

        public virtual ICollection<ClinicalPAT> ClinicalPATs { get; set; }



    }
}
@model Assets.Areas.Clinical.Models.ClinicalAsset
<link href="~/Content/bootstrap-timepicker.min.css" rel="stylesheet" type="text/css" />
@{
    ViewBag.Title = "Create Asset";
    ViewBag.Current = "Create Asset";
}


<div class="pageheader">
    <h2><i class="fa fa-pencil"></i>Add Clinical Assets</h2>
    <div class="breadcrumb-wrapper">
        <span class="label">You are here:</span>
        <ol class="breadcrumb">
            <li>Asset Management System</li>
            <li class="active">Clinical Assets / Add Asset</li>
        </ol>
    </div>
</div>
<div class="contentpanel">
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()



        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="minimize">&minus;</a>
                    </div>
                    <h4 class="panel-title">Create an asset.</h4>
                    <p>Please fill in the required boxes as a minimum.<text style="color:red;"> * </text> </p>
                </div>
                @Html.ValidationSummary()
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                @Html.LabelFor(model => model.AssetTypeID, "Asset Type:", new { @class = "control-label" })
                                @Html.DropDownListFor(model => model.AssetTypeID, (SelectList)ViewBag.AssetTypeDropDown, "Please Select From The List", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.AssetTypeID, "", new { @class = "text-danger" })
                            </div>
                        </div><!-- col-sm-6 -->

                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddProduct">Select Product:</label> <label id="lbltipAddProduct2" style="display:none;">Enter Product:</label>   
                                <label id="hideproductbutton" style="float: right;"><i class="myClass fa fa-edit" id="product"></i></label>
                                <label id="shownewproductbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="product2"></i></label>
                                <div id="Product">
                                    @Html.DropDownListFor(model => model.ProductID, (SelectList)ViewBag.ProductDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ProductID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-product" style="display:none;">
                                    @Html.EditorFor(model => model.ProductName.ProductName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Product Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ProductName.ProductName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                    </div><!-- row -->
                    <div id="inputs-for-filters1">

                        <div class="form-group">
                            @Html.EditorFor(model => model.Filter)
                            @Html.LabelFor(model => model.Filter, "Filter Required?")
                            @Html.ValidationMessageFor(model => model.Filter)
                        </div>

                    </div>
                    <div id="inputs-for-filters2">

                        <div class="form-group">
                            @Html.EditorFor(model => model.Filter)
                            @Html.LabelFor(model => model.Filter, "Filter Required?")
                            @Html.ValidationMessageFor(model => model.Filter)
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddManufacturer">Select Manufacturer:</label> <label id="lbltipAddManufacturer2" style="display:none;">Enter Manufacturer:</label>   
                                <label id="hidemanufacturerbutton" style="float: right;"><i class="myClass fa fa-edit" id="manufacturer"></i></label>
                                <label id="shownewmanufacturerbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="manufacturer2"></i></label>
                                <div id="Manufacturer">
                                    @Html.DropDownListFor(model => model.ManufacturerID, (SelectList)ViewBag.ManufacturerDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ManufacturerID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-manufacturer" style="display:none;">
                                    @Html.EditorFor(model => model.ManufacturerName.ManufacturerName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ManufacturerName.ManufacturerName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddModel">Select Model:</label> <label id="lbltipAddModel2" style="display:none;">Enter Model Type:</label>  
                                <label id="hidemodelbutton" style="float: right;"><i class="myClass fa fa-edit" id="model"></i></label>
                                <label id="shownewmodelbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="model2"></i></label>
                                <div id="Model">
                                    @Html.DropDownListFor(model => model.ModelID, (SelectList)ViewBag.ModelDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ModelID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-model" style="display:none;">
                                    @Html.EditorFor(model => model.ModelName.ModelName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ModelName.ModelName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                    </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label id="lbltipAddSupplier">Select Supplier:</label> <label id="lbltipAddSupplier2" style="display:none;">Enter Supplier:</label>  
                                    <label id="hidesupplierbutton" style="float: right;"><i class="myClass fa fa-edit" id="supplier"></i></label>
                                    <label id="shownewsupplierbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="supplier2"></i></label>
                                    <div id="Supplier">
                                        @Html.DropDownListFor(model => model.SupplierID, (SelectList)ViewBag.SupplierDropDown, "Please Select From The List", new { @class = "form-control" })
                                        @Html.ValidationMessageFor(model => model.SupplierID, "", new { @class = "text-danger" })
                                    </div>
                                    <div class="js-supplier" style="display:none;">
                                        @Html.EditorFor(model => model.SupplierName.SupplierName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Supplier Name Here", disabled = "disabled" } })
                                        @Html.ValidationMessageFor(model => model.SupplierName.SupplierName, "", new { @class = "text-danger" })
                                    </div>
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.SerialNo, "Serial No:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.SerialNo, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.SerialNo, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.PurchaseDate, "Purchase Date:", new { @class = "control-label" })
                                    @Html.TextBoxFor(m => m.PurchaseDate, new { @class = "form-control datepicker", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.PurchaseDate, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.PoNo, "Purchase OrderNo:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.PoNo, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.PoNo, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.BudgetCodeID, "Budget Code:", new { @class = "control-label" })
                                    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Costing, "Cost:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.Costing, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.Costing, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.TeamID, "Team:", new { @class = "control-label" })
                                    @Html.DropDownListFor(model => model.TeamID, ViewBag.TeamList as SelectList, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.TeamID, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label id="lbltipAddStaff">Select Staff Member:</label> <label id="lbltipAddStaff2" style="display:none;">Enter Staff Member Name:</label>   
                                    <label id="hidestaffbutton" Style="float: right;"><i class="myClass fa fa-edit" id="staff"></i></label>
                                    <label id="shownewstaffbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="staff2"></i></label>
                                    <div id="Staff">
                                        @Html.DropDownListFor(model => model.StaffID, (SelectList)ViewBag.StaffDropDown, "Please Select From The List", new { @class = "form-control" })
                                        @Html.ValidationMessageFor(model => model.StaffID, "", new { @class = "text-danger" })
                                    </div>
                                    <div class="js-staff" style="display:none;">
                                        @Html.EditorFor(model => model.StaffName.StaffName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                        @Html.ValidationMessageFor(model => model.StaffName.StaffName, "", new { @class = "text-danger" })
                                    </div>
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                    </div><!-- panel-body -->

                <div class="panel-footer">
                    <input type="submit" value="Create" class="btn btn-primary" />
                </div>

            </div>
        </div>
    }
</div><!-- panel -->

@section Scripts {
    <script src="~/Scripts/jquery-ui-1.10.3.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

        @Scripts.Render("~/bundles/jqueryval")

    <script>

        // Date Picker
        jQuery('#PurchaseDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#WarrantyEndDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#InspectionDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#InspectionDueDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#datepicker-inline').datepicker();

        jQuery('#datepicker-multiple').datepicker({
            numberOfMonths: 3,
            showButtonPanel: true
        });



        $(document).ready(function () {
            $("#inputs-for-filters1").hide();
            $("#inputs-for-filters2").hide();

            $("#AssetTypeID").change(function () {
                if ($("#AssetTypeID").val() == "3") {
                    $("#inputs-for-filters1").show();
                }
                else {
                    $("#inputs-for-filters1").hide();
                }
            });

            $("#ProductID").change(function () {
                if ($("#ProductID").val() == "24") {
                    $("#inputs-for-filters2").show();
                }
                else {
                    $("#inputs-for-filters2").hide();
                }
            });

        });



            $(document).ready(function () {
                $("#staff").click(function () {
                    $("#Staff").toggle();
                    $(".js-staff").toggle();
                    $('#lbltipAddStaff').toggle();
                    $('#lbltipAddStaff2').toggle();
                    $(".js-staff input[type='text']").attr("disabled", false);
                    $("#hidestaffbutton").toggle();
                    $("#shownewstaffbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#staff2").click(function () {
                    $("#Staff").toggle();
                    $(".js-staff").toggle();
                    $('#lbltipAddStaff').toggle();
                    $('#lbltipAddStaff2').toggle();
                    $(".js-staff input[type='text']").attr("disabled", true);
                    $("#hidestaffbutton").toggle();
                    $("#shownewstaffbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#model").click(function () {
                    $("#Model").toggle();
                    $(".js-model").toggle();
                    $('#lbltipAddModel').toggle();
                    $('#lbltipAddModel2').toggle();
                    $(".js-model input[type='text']").attr("disabled", false);
                    $("#hidemodelbutton").toggle();
                    $("#shownewmodelbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#model2").click(function () {
                    $("#Model").toggle();
                    $(".js-model").toggle();
                    $('#lbltipAddModel').toggle();
                    $('#lbltipAddModel2').toggle();
                    $(".js-model input[type='text']").attr("disabled", true);
                    $("#hidemodelbutton").toggle();
                    $("#shownewmodelbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#manufacturer").click(function () {
                    $("#Manufacturer").toggle();
                    $(".js-manufacturer").toggle();
                    $('#lbltipAddManufacturer').toggle();
                    $('#lbltipAddManufacturer2').toggle();
                    $(".js-manufacturer input[type='text']").attr("disabled", false);
                    $("#hidemanufacturerbutton").toggle();
                    $("#shownewmanufacturerbutton").toggle();
                });
            });


            $(document).ready(function () {
                $("#manufacturer2").click(function () {
                    $("#Manufacturer").toggle();
                    $(".js-manufacturer").toggle();
                    $('#lbltipAddManufacturer').toggle();
                    $('#lbltipAddManufacturer2').toggle();
                    $(".js-manufacturer input[type='text']").attr("disabled", true);
                    $("#hidemanufacturerbutton").toggle();
                    $("#shownewmanufacturerbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#product").click(function () {
                    $("#Product").toggle();
                    $(".js-product").toggle();
                    $('#lbltipAddProduct').toggle();
                    $('#lbltipAddProduct2').toggle();
                    $(".js-product input[type='text']").attr("disabled", false);
                    $("#hideproductbutton").toggle();
                    $("#shownewproductbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#product2").click(function () {
                    $("#Product").toggle();
                    $(".js-product").toggle();
                    $('#lbltipAddProduct').toggle();
                    $('#lbltipAddProduct2').toggle();
                    $(".js-product input[type='text']").attr("disabled", true);
                    $("#hideproductbutton").toggle();
                    $("#shownewproductbutton").toggle();
                });
            });


            $(document).ready(function () {
                $("#supplier").click(function () {
                    $("#Supplier").toggle();
                    $(".js-supplier").toggle(); 
                    $('#lbltipAddSupplier').toggle();
                    $('#lbltipAddSupplier2').toggle();
                    $(".js-supplier input[type='text']").attr("disabled", false);
                    $("#hidesupplierbutton").toggle();
                    $("#shownewsupplierbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#supplier2").click(function () {
                    $("#Supplier").toggle();
                    $(".js-supplier").toggle();
                    $('#lbltipAddSupplier').toggle();
                    $('#lbltipAddSupplier2').toggle();
                    $(".js-supplier input[type='text']").attr("disabled", true);
                    $("#hidesupplierbutton").toggle();
                    $("#shownewsupplierbutton").toggle();
                });
            });



    </script>
}

创建表单:

using Assets.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace Assets.Areas.Clinical.Models
{
    public class ClinicalAsset
    {

        [Key]
        public int ClinicalAssetID { get; set; }
        public int AssetTypeID { get; set; }
        public int? ProductID { get; set; }
        public int? ManufacturerID { get; set; }
        public int? ModelID{ get; set; }
        public int? SupplierID { get; set; }
        [StringLength(100, MinimumLength = 2)]
        public string SerialNo { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{0:dd/MM/yy}", ApplyFormatInEditMode = true)]
        public DateTime? PurchaseDate { get; set; }
        [StringLength(100, MinimumLength = 2)]
        public string PoNo { get; set; }
        [DisplayFormat(DataFormatString = "{0:c2}", ApplyFormatInEditMode = true)]
        public decimal? Costing { get; set; }
        public int? TeamID { get; set; }
        public int? BudgetCodeID { get; set; }
        public int? StaffID { get; set; }
        public bool? Filter { get; set; }



        public virtual Model ModelName { get; set; }
        public virtual Model AssetAssignmentID { get; set; }
        public virtual BudgetCode BudgetCodeJoinColumn { get; set; }
        public virtual Product ProductName { get; set; }
        public virtual AssetType AssetTypeName { get; set; }
        public virtual Manufacturer ManufacturerName { get; set; }
        public virtual Staff StaffName { get; set; }
        public virtual Team TeamName { get; set; }
        public virtual Supplier SupplierName { get; set; }

        public virtual ICollection<ClinicalPAT> ClinicalPATs { get; set; }



    }
}
@model Assets.Areas.Clinical.Models.ClinicalAsset
<link href="~/Content/bootstrap-timepicker.min.css" rel="stylesheet" type="text/css" />
@{
    ViewBag.Title = "Create Asset";
    ViewBag.Current = "Create Asset";
}


<div class="pageheader">
    <h2><i class="fa fa-pencil"></i>Add Clinical Assets</h2>
    <div class="breadcrumb-wrapper">
        <span class="label">You are here:</span>
        <ol class="breadcrumb">
            <li>Asset Management System</li>
            <li class="active">Clinical Assets / Add Asset</li>
        </ol>
    </div>
</div>
<div class="contentpanel">
@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()



        <div class="col-md-6">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <div class="panel-btns">
                        <a href="" class="minimize">&minus;</a>
                    </div>
                    <h4 class="panel-title">Create an asset.</h4>
                    <p>Please fill in the required boxes as a minimum.<text style="color:red;"> * </text> </p>
                </div>
                @Html.ValidationSummary()
                <div class="panel-body">
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                @Html.LabelFor(model => model.AssetTypeID, "Asset Type:", new { @class = "control-label" })
                                @Html.DropDownListFor(model => model.AssetTypeID, (SelectList)ViewBag.AssetTypeDropDown, "Please Select From The List", new { @class = "form-control" })
                                @Html.ValidationMessageFor(model => model.AssetTypeID, "", new { @class = "text-danger" })
                            </div>
                        </div><!-- col-sm-6 -->

                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddProduct">Select Product:</label> <label id="lbltipAddProduct2" style="display:none;">Enter Product:</label>   
                                <label id="hideproductbutton" style="float: right;"><i class="myClass fa fa-edit" id="product"></i></label>
                                <label id="shownewproductbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="product2"></i></label>
                                <div id="Product">
                                    @Html.DropDownListFor(model => model.ProductID, (SelectList)ViewBag.ProductDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ProductID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-product" style="display:none;">
                                    @Html.EditorFor(model => model.ProductName.ProductName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Product Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ProductName.ProductName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                    </div><!-- row -->
                    <div id="inputs-for-filters1">

                        <div class="form-group">
                            @Html.EditorFor(model => model.Filter)
                            @Html.LabelFor(model => model.Filter, "Filter Required?")
                            @Html.ValidationMessageFor(model => model.Filter)
                        </div>

                    </div>
                    <div id="inputs-for-filters2">

                        <div class="form-group">
                            @Html.EditorFor(model => model.Filter)
                            @Html.LabelFor(model => model.Filter, "Filter Required?")
                            @Html.ValidationMessageFor(model => model.Filter)
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddManufacturer">Select Manufacturer:</label> <label id="lbltipAddManufacturer2" style="display:none;">Enter Manufacturer:</label>   
                                <label id="hidemanufacturerbutton" style="float: right;"><i class="myClass fa fa-edit" id="manufacturer"></i></label>
                                <label id="shownewmanufacturerbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="manufacturer2"></i></label>
                                <div id="Manufacturer">
                                    @Html.DropDownListFor(model => model.ManufacturerID, (SelectList)ViewBag.ManufacturerDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ManufacturerID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-manufacturer" style="display:none;">
                                    @Html.EditorFor(model => model.ManufacturerName.ManufacturerName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ManufacturerName.ManufacturerName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                        <div class="col-sm-6">
                            <div class="form-group">
                                <label id="lbltipAddModel">Select Model:</label> <label id="lbltipAddModel2" style="display:none;">Enter Model Type:</label>  
                                <label id="hidemodelbutton" style="float: right;"><i class="myClass fa fa-edit" id="model"></i></label>
                                <label id="shownewmodelbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="model2"></i></label>
                                <div id="Model">
                                    @Html.DropDownListFor(model => model.ModelID, (SelectList)ViewBag.ModelDropDown, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.ModelID, "", new { @class = "text-danger" })
                                </div>
                                <div class="js-model" style="display:none;">
                                    @Html.EditorFor(model => model.ModelName.ModelName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                    @Html.ValidationMessageFor(model => model.ModelName.ModelName, "", new { @class = "text-danger" })
                                </div>
                            </div>
                        </div><!-- col-sm-6 -->
                    </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label id="lbltipAddSupplier">Select Supplier:</label> <label id="lbltipAddSupplier2" style="display:none;">Enter Supplier:</label>  
                                    <label id="hidesupplierbutton" style="float: right;"><i class="myClass fa fa-edit" id="supplier"></i></label>
                                    <label id="shownewsupplierbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="supplier2"></i></label>
                                    <div id="Supplier">
                                        @Html.DropDownListFor(model => model.SupplierID, (SelectList)ViewBag.SupplierDropDown, "Please Select From The List", new { @class = "form-control" })
                                        @Html.ValidationMessageFor(model => model.SupplierID, "", new { @class = "text-danger" })
                                    </div>
                                    <div class="js-supplier" style="display:none;">
                                        @Html.EditorFor(model => model.SupplierName.SupplierName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Supplier Name Here", disabled = "disabled" } })
                                        @Html.ValidationMessageFor(model => model.SupplierName.SupplierName, "", new { @class = "text-danger" })
                                    </div>
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.SerialNo, "Serial No:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.SerialNo, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.SerialNo, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.PurchaseDate, "Purchase Date:", new { @class = "control-label" })
                                    @Html.TextBoxFor(m => m.PurchaseDate, new { @class = "form-control datepicker", autocomplete = "off" })
                                    @Html.ValidationMessageFor(model => model.PurchaseDate, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.PoNo, "Purchase OrderNo:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.PoNo, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.PoNo, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.BudgetCodeID, "Budget Code:", new { @class = "control-label" })
                                    @Html.DropDownListFor(m => m.BudgetCodeID, (SelectList)ViewBag.BudgetsList, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.BudgetCodeID, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.Costing, "Cost:", new { @class = "control-label" })
                                    @Html.EditorFor(model => model.Costing, new { htmlAttributes = new { @class = "form-control" } })
                                    @Html.ValidationMessageFor(model => model.Costing, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="form-group">
                                    @Html.LabelFor(model => model.TeamID, "Team:", new { @class = "control-label" })
                                    @Html.DropDownListFor(model => model.TeamID, ViewBag.TeamList as SelectList, "Please Select From The List", new { @class = "form-control" })
                                    @Html.ValidationMessageFor(model => model.TeamID, "", new { @class = "text-danger" })
                                </div>
                            </div><!-- col-sm-6 -->
                            <div class="col-sm-6">
                                <div class="form-group">
                                    <label id="lbltipAddStaff">Select Staff Member:</label> <label id="lbltipAddStaff2" style="display:none;">Enter Staff Member Name:</label>   
                                    <label id="hidestaffbutton" Style="float: right;"><i class="myClass fa fa-edit" id="staff"></i></label>
                                    <label id="shownewstaffbutton" Style="float: right; display:none;"><i class="glyphicon glyphicon-remove-circle" id="staff2"></i></label>
                                    <div id="Staff">
                                        @Html.DropDownListFor(model => model.StaffID, (SelectList)ViewBag.StaffDropDown, "Please Select From The List", new { @class = "form-control" })
                                        @Html.ValidationMessageFor(model => model.StaffID, "", new { @class = "text-danger" })
                                    </div>
                                    <div class="js-staff" style="display:none;">
                                        @Html.EditorFor(model => model.StaffName.StaffName, new { htmlAttributes = new { @class = "form-control", @placeholder = "Enter Name Here", disabled = "disabled" } })
                                        @Html.ValidationMessageFor(model => model.StaffName.StaffName, "", new { @class = "text-danger" })
                                    </div>
                                </div>
                            </div><!-- col-sm-6 -->
                        </div><!-- row -->
                    </div><!-- panel-body -->

                <div class="panel-footer">
                    <input type="submit" value="Create" class="btn btn-primary" />
                </div>

            </div>
        </div>
    }
</div><!-- panel -->

@section Scripts {
    <script src="~/Scripts/jquery-ui-1.10.3.min.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>

        @Scripts.Render("~/bundles/jqueryval")

    <script>

        // Date Picker
        jQuery('#PurchaseDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#WarrantyEndDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#InspectionDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#InspectionDueDate').datepicker({ dateFormat: 'dd/mm/yy' });
        jQuery('#datepicker-inline').datepicker();

        jQuery('#datepicker-multiple').datepicker({
            numberOfMonths: 3,
            showButtonPanel: true
        });



        $(document).ready(function () {
            $("#inputs-for-filters1").hide();
            $("#inputs-for-filters2").hide();

            $("#AssetTypeID").change(function () {
                if ($("#AssetTypeID").val() == "3") {
                    $("#inputs-for-filters1").show();
                }
                else {
                    $("#inputs-for-filters1").hide();
                }
            });

            $("#ProductID").change(function () {
                if ($("#ProductID").val() == "24") {
                    $("#inputs-for-filters2").show();
                }
                else {
                    $("#inputs-for-filters2").hide();
                }
            });

        });



            $(document).ready(function () {
                $("#staff").click(function () {
                    $("#Staff").toggle();
                    $(".js-staff").toggle();
                    $('#lbltipAddStaff').toggle();
                    $('#lbltipAddStaff2').toggle();
                    $(".js-staff input[type='text']").attr("disabled", false);
                    $("#hidestaffbutton").toggle();
                    $("#shownewstaffbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#staff2").click(function () {
                    $("#Staff").toggle();
                    $(".js-staff").toggle();
                    $('#lbltipAddStaff').toggle();
                    $('#lbltipAddStaff2').toggle();
                    $(".js-staff input[type='text']").attr("disabled", true);
                    $("#hidestaffbutton").toggle();
                    $("#shownewstaffbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#model").click(function () {
                    $("#Model").toggle();
                    $(".js-model").toggle();
                    $('#lbltipAddModel').toggle();
                    $('#lbltipAddModel2').toggle();
                    $(".js-model input[type='text']").attr("disabled", false);
                    $("#hidemodelbutton").toggle();
                    $("#shownewmodelbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#model2").click(function () {
                    $("#Model").toggle();
                    $(".js-model").toggle();
                    $('#lbltipAddModel').toggle();
                    $('#lbltipAddModel2').toggle();
                    $(".js-model input[type='text']").attr("disabled", true);
                    $("#hidemodelbutton").toggle();
                    $("#shownewmodelbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#manufacturer").click(function () {
                    $("#Manufacturer").toggle();
                    $(".js-manufacturer").toggle();
                    $('#lbltipAddManufacturer').toggle();
                    $('#lbltipAddManufacturer2').toggle();
                    $(".js-manufacturer input[type='text']").attr("disabled", false);
                    $("#hidemanufacturerbutton").toggle();
                    $("#shownewmanufacturerbutton").toggle();
                });
            });


            $(document).ready(function () {
                $("#manufacturer2").click(function () {
                    $("#Manufacturer").toggle();
                    $(".js-manufacturer").toggle();
                    $('#lbltipAddManufacturer').toggle();
                    $('#lbltipAddManufacturer2').toggle();
                    $(".js-manufacturer input[type='text']").attr("disabled", true);
                    $("#hidemanufacturerbutton").toggle();
                    $("#shownewmanufacturerbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#product").click(function () {
                    $("#Product").toggle();
                    $(".js-product").toggle();
                    $('#lbltipAddProduct').toggle();
                    $('#lbltipAddProduct2').toggle();
                    $(".js-product input[type='text']").attr("disabled", false);
                    $("#hideproductbutton").toggle();
                    $("#shownewproductbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#product2").click(function () {
                    $("#Product").toggle();
                    $(".js-product").toggle();
                    $('#lbltipAddProduct').toggle();
                    $('#lbltipAddProduct2').toggle();
                    $(".js-product input[type='text']").attr("disabled", true);
                    $("#hideproductbutton").toggle();
                    $("#shownewproductbutton").toggle();
                });
            });


            $(document).ready(function () {
                $("#supplier").click(function () {
                    $("#Supplier").toggle();
                    $(".js-supplier").toggle(); 
                    $('#lbltipAddSupplier').toggle();
                    $('#lbltipAddSupplier2').toggle();
                    $(".js-supplier input[type='text']").attr("disabled", false);
                    $("#hidesupplierbutton").toggle();
                    $("#shownewsupplierbutton").toggle();
                });
            });

            $(document).ready(function () {
                $("#supplier2").click(function () {
                    $("#Supplier").toggle();
                    $(".js-supplier").toggle();
                    $('#lbltipAddSupplier').toggle();
                    $('#lbltipAddSupplier2').toggle();
                    $(".js-supplier input[type='text']").attr("disabled", true);
                    $("#hidesupplierbutton").toggle();
                    $("#shownewsupplierbutton").toggle();
                });
            });



    </script>
}

@model Assets.Areas.Clinical.Models.ClinicalAsset
@{
ViewBag.Title=“创建资产”;
ViewBag.Current=“创建资产”;
}
增加临床资产
你在这里:
  • 资产管理系统
  • 临床资产/添加资产
  • @使用(Html.BeginForm()) { @Html.AntiForgeryToken() 创建一个资产。 请至少填写所需的方框。*

    @Html.ValidationSummary() @LabelFor(model=>model.AssetTypeID,“资产类型:”,新的{@class=“control label”}) @Html.DropDownListFor(model=>model.AssetTypeID,(SelectList)ViewBag.AssetTypeDropDown,“请从列表中选择”,新建{@class=“form control”}) @Html.ValidationMessageFor(model=>model.AssetTypeID,“,new{@class=“text danger”}) 选择产品:输入产品: @Html.DropDownListFor(model=>model.ProductID,(SelectList)ViewBag.ProductDropDown,“请从列表中选择”,新建{@class=“form control”}) @Html.ValidationMessageFor(model=>model.ProductID,“,new{@class=“text danger”}) @Html.EditorFor(model=>model.ProductName.ProductName,new{htmlAttributes=new{@class=“form control”,@placeholder=“在此处输入产品名”,disabled=“disabled”}) @Html.ValidationMessageFor(model=>model.ProductName.ProductName,“,新{@class=“text danger”}) @EditorFor(model=>model.Filter) @LabelFor(model=>model.Filter,“需要筛选?”) @Html.ValidationMessageFor(model=>model.Filter) @EditorFor(model=>model.Filter) @LabelFor(model=>model.Filter,“需要筛选?”) @Html.ValidationMessageFor(model=>model.Filter) 选择制造商:输入制造商: @DropDownListFor(model=>model.ManufacturerID,(SelectList)ViewBag.ManufacturerDropDown,“请从列表中选择”,新建{@class=“form control”}) @Html.ValidationMessageFor(model=>model.ManufacturerID,“,new{@class=“text danger”}) @EditorFor(model=>model.ManufacturerName.ManufacturerName,new{htmlAttributes=new{@class=“form control”,@placeholder=“此处输入名称”,disabled=“disabled”}) @Html.ValidationMessageFor(model=>model.ManufacturerName.ManufacturerName,“,新的{@class=“text danger”}) 选择模型:输入模型类型: @Html.DropDownListFor(model=>model.ModelID,(SelectList)ViewBag.ModelDropDown,“请从列表中选择”,新建{@class=“form control”}) @Html.ValidationMessageFor(model=>model.ModelID,“,new{@class=“text danger”}) @EditorFor(model=>model.ModelName.ModelName,new{htmlAttributes=new{@class=“formcontrol”,@placeholder=“此处输入名称”,disabled=“disabled”}) @Html.ValidationMessageFor(model=>model.ModelName.ModelName,”,新的{@class=“text danger”})