none
ASP MVC HTML button - add newline RRS feed

  • Question

  • I have tried every possible variation of adding a newline into an HTML button.  The browser developer view shows that either Bootstrap or another js library replaces whatever I'm trying with the safer <br/> options.

    I do not want to use CSS, I am simply wanting to create a row of buttons on a page with lines extracted from a database and assembled into a set of rows on the button.

    It's driving me mad since I can't figure out what the right request should be.

    I am sure that this must be a simple issue - getting to code rows of data to appear on a button.  

    The data comes from a controller like this:
    public ActionResult ListInstallers()
            {
                List<InstallerModel> varInstaller = new List<InstallerModel>();
                varInstaller.Add(new InstallerModel { InstallerFullName = "Norbet",  Suburb= "Bellville (3) <br/> Belhar (2)..." });      // Attempt#1
                varInstaller.Add(new InstallerModel { InstallerFullName = "Jacque",  Suburb = "Bellville (3) &#013; Belhar (2)..." });  // Attempt#2
                varInstaller.Add(new InstallerModel { InstallerFullName = "Peter",Suburb = "Bellville (3) \r\n Belhar (2)..." });         // Attempt#3
                varInstaller.Add(new InstallerModel { InstallerFullName = "Thando", Suburb = "Bellville (3) &#010; Belhar (2)..." });// Attempt#4
                return View(varInstaller);
            }

    This is then pushed into a cshtml page in the following loop:
        </tr>
     @foreach (var item in Model) {
        <tr> <td>@item.InstallerFullName</td>
            @for (var i = 1; i < 7; i++)
            {<td>
                    <button class="dbBtn" type="button" style="height:150px; width:150px" >@item.Suburb</button>
                </td>}
         </tr>

    This is however consistenly translated by the MVC, BOOTSTRAP, JQuery environment into elements where the newline code is replaced with  &lt;br/&gt; 

    I can understand what it is doing, but cannot figure out where or how to tell is to just use the Char(13) and not replace it with the "safer" code.

    Can you help me understand this please?

    • Changed type KareninstructorMVP Tuesday, December 3, 2019 8:30 PM This is a question
    • Edited by Sean Achim Tuesday, December 3, 2019 8:55 PM
    • Moved by CoolDadTx Tuesday, December 3, 2019 10:39 PM ASP.NET related
    Tuesday, December 3, 2019 8:27 PM

All replies

  • Have you considered asking here https://forums.asp.net/

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, December 3, 2019 9:14 PM
  • Hi Karen

    Yes I will post the question there as well.  I'm currently just struggling to create my account on that forum.

    Tuesday, December 3, 2019 9:37 PM