Convert textbox type to password in asp.net mvc

后端 未结 11 2485
感情败类
感情败类 2020-12-18 18:13

How do I convert a textbox type to password in asp.net mvc?

相关标签:
11条回答
  • 2020-12-18 18:16

    There are many types of using password-typed textboxes in ASP. NET MVC

    With html controls it would be like;

    <input type="password" name="xx" id="yy">
    

    With Razor-syntax it would be like;

    @Html.Password(name, value, html_attributes)
    

    Or in a strongly typed view you could write

    @Html.PasswordFor(model=>model.Password)
    
    0 讨论(0)
  • 2020-12-18 18:17

    Another way is to add @type = password to your html.texbox() attributes like so:

    before converting:

    @Html.TextBox("mypass", null, new { @class = "" })
    

    After converting:

    @Html.TextBox("mypass", null, new { @class = "", @type = password })
    

    This will mask your text box text with circles instead of text. It does this, because the @type = password attribute tells your text box that it is of type "password".

    This method of converting your text box to type password is an easy quick way to to make the conversion from your standard razor form text box.

    0 讨论(0)
  • 2020-12-18 18:22

    In .cshtml file:

    @Html.PasswordFor(modal => modal.Password)
    
    0 讨论(0)
  • 2020-12-18 18:26

    Just write in Razor View i.e. in .cshtml file below line

      @Html.PasswordFor(m=>m.Password)
    

    Here m is model object and password is the password field name.

    0 讨论(0)
  • 2020-12-18 18:27

    Either use the HTML helper function Password:

    <%= Html.Password("Password") %>
    

    or use the type parameter on an input field:

    <input name="password" type="password" />
    

    See listings 4 and 5 on this page

    0 讨论(0)
  • 2020-12-18 18:27

    below is extention based on html helper:

    before converting:

    @Html.TextBox("mypass", null, new { style = "width: 200px;" })
    

    After converting:

    @Html.Password("mypass", null, new { style = "width:200px;" })
    

    hope helps someone.

    0 讨论(0)
提交回复
热议问题