takachaa / .net-Framework

0 stars 0 forks source link

【MVC】基本的なモデル構造 #11

Open takachaa opened 7 years ago

takachaa commented 7 years ago

以下が基本的なモデル構造

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication1.Models
{
    public class Member
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string Email { get; set; }

        public DateTime Birth { get; set; }

        public bool Married { get; set; }

        public string Memo { get; set; }
    }
}
takachaa commented 7 years ago

ビュー上にて以下の記述の際にカラム名を日本語にした場合は

@Html.DisplayNameFor(model => model.Name)

以下のように修正する ※「using System.ComponentModel」を忘れないで

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;

namespace WebApplication1.Models
{
    public class Member
    {
        public int Id { get; set; }

        [DisplayName("名前")]
        public string Name { get; set; }

        [DisplayName("メールアドレス")]
        public string Email { get; set; }

        [DisplayName("生年月日")]
        public DateTime Birth { get; set; }

        [DisplayName("既婚")]
        public bool Married { get; set; }

        [DisplayName("自己紹介")]
        public string Memo { get; set; }
    }
}