مرجع تخصصی برنامه نویسان

بزرگترین انجمن برنامه نویسان فارسی زبان

عدم تغییر لیبل با وجود DataAnnotations و استفاده از Scaffolding

یکشنبه, 26 شهریور 1396 21:20

عدم تغییر لیبل با وجود DataAnnotations و استفاده از Scaffolding

با توجه به تعریف 

[Display(Name = " ")] بعد از ساخت صفحه به صورت لاتین نمایش داده میشود لاز به ذکر که این دو فیلد FK جداول دیگه هستند

دوشنبه, 27 شهریور 1396 09:44

این مدل شماست ؟

لطفا کد کامل ویو و مدل را قرار دهید

دوشنبه, 27 شهریور 1396 12:11
[Key]
        public int PersonId { get; set; }

        public int Userid { get; set; }


        [Display(Name = "نام مسیر")]
        [Required(ErrorMessage = "لطفا {0}را وارد نمایید")]
        public int RoutId { get; set; }


        [Display(Name = "نام ایستگاه")]
        [Required(ErrorMessage = "لطفا {0}را وارد نمایید")]
        public int StationId { get; set; }

        [Display(Name = "تاریخ ویرایش")]
        public DateTime DateInput { get; set; }

        [Display(Name = "تاریخ ویرایش")]
        public DateTime DateEdit { get; set; }

        //foreignkey Rout_service in tableTeacher_Service
        [ForeignKey("RoutId")]
        public virtual Rout_Service RoutService { get; set; }

        //foreignkey Rout_service in tableTeacher_Service
        [ForeignKey("StationId")]
        public virtual Station_service StationService { get; set; }

        //foreignkey User in table Rout_service
        [ForeignKey("Userid")]
        public virtual Users user { get; set; }
        public Teacher_Service()
        { }

<hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        @*<div class="form-group">
            @Html.LabelFor(model => model.Userid, "Userid", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("Userid", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-danger" })
            </div>
        </div>*@

        <div class="form-group">
            @Html.LabelFor(model => model.RoutId, "RoutId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("RoutId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.RoutId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.StationId, "StationId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("StationId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.StationId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateInput, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateInput, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateInput, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateEdit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateEdit, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateEdit, "", new { @class = "text-danger" })
            </div>
        </div>

دوشنبه, 27 شهریور 1396 12:38

عرض کردم کد کامل نه بخشی از کد

دوشنبه, 27 شهریور 1396 15:55
 
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataLayer
{
public class Teacher_Service
{
[Key]
public int PersonId { get; set; }
public int Userid { get; set; }
[Display(Name = "نام مسیر")]
[Required(ErrorMessage = "لطفا {0}را وارد نمایید")]
public int RoutId { get; set; }
[Display(Name = "نام ایستگاه")]
[Required(ErrorMessage = "لطفا {0}را وارد نمایید")]
public int StationId { get; set; }
[Display(Name = "تاریخ ویرایش")]
public DateTime DateInput { get; set; }
[Display(Name = "تاریخ ویرایش")]
public DateTime DateEdit { get; set; }
//foreignkey Rout_service in tableTeacher_Service
[ForeignKey("RoutId")]
public virtual Rout_Service RoutService { get; set; }
//foreignkey Rout_service in tableTeacher_Service
[ForeignKey("StationId")]
public virtual Station_service StationService { get; set; }
//foreignkey User in table Rout_service
[ForeignKey("Userid")]
public virtual Users user { get; set; }
public Teacher_Service()
{ }
}
}

-------------------------------------------------------------------------------

@model DataLayer.Teacher_Service

@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Create</h2>

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Teacher_Service</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Userid, "Userid", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("Userid", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.RoutId, "RoutId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("RoutId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.RoutId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.StationId, "StationId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("StationId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.StationId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateInput, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateInput, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateInput, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateEdit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateEdit, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateEdit, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="ثبت اطلاعات" value="Create" class="btn btn-default" />
            </div>
        </div>
    </div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
دوشنبه, 27 شهریور 1396 16:40

به شکل زیر اصلاح کنید

@using (Html.BeginForm()) 
{
    @Html.AntiForgeryToken()
    
    <div class="form-horizontal">
        <h4>Teacher_Service</h4>
        <hr />
        @Html.ValidationSummary(true, "", new { @class = "text-danger" })
        <div class="form-group">
            @Html.LabelFor(model => model.Userid, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("Userid", null, htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.Userid, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.RoutId, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("RoutId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.RoutId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.StationId, "StationId", htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.DropDownList("StationId", null, "-- انتخاب ---", htmlAttributes: new { @class = "form-control" })
                @Html.ValidationMessageFor(model => model.StationId, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateInput, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateInput, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateInput, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            @Html.LabelFor(model => model.DateEdit, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="col-md-10">
                @Html.EditorFor(model => model.DateEdit, new { htmlAttributes = new { @class = "form-control" } })
                @Html.ValidationMessageFor(model => model.DateEdit, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="form-group">
            <div class="col-md-offset-2 col-md-10">
                <input type="ثبت اطلاعات" value="Create" class="btn btn-default" />
            </div>
        </div>
    

ارسال پاسخ برای این تاپیک

ارسال پاسخ مخصوص اعضا سایت می باشد ! میتوانید با حساب کاربری خود وارد سایت شده یا ثبت نام کنید