How do I add placeholder text from the model into a MVC view?

后端 未结 9 1243
余生分开走
余生分开走 2021-02-05 12:43

I have a model:

[DataType(DataType.EmailAddress)]
[DisplayFormat(ConvertEmptyStringToNull = true)]
[Display(Prompt = \"Email Address\")]
public string Email { ge         


        
9条回答
  •  自闭症患者
    2021-02-05 13:05

    In your controller method that renders view say

    ViewData["Name"] = "blabbity blah";

    then

    @Html.TextBoxFor(u => u.Company, new { @placeholder = @ViewData["Name"] })

    Actually better yet you can do this.

     public ActionResult Index()
        {              
              NewLogin n = new ClassModel().PopModel();
              n.Company = "fsdfsdf";
    
              return View(n);
        }
    

    @Html.TextBoxFor(u => u.Company, new { @placeholder = Model.Company })

提交回复
热议问题