Solved

Types of HTML text boxes when using MVC with .Net

Posted on 2016-08-21
2
35 Views
Last Modified: 2016-08-21
I have two different text boxes below. I am under the impression that they are both HTML text boxes. I am using Microsoft.net,
and MVC with C#.

I want to place these text boxes in a partial view. I have noticed that the <input type ...> text box when used as a partial view will be displayed in every .cshmtl page in the project, and the other text box type @Html will display in only the .cshtml page that uses the partial view. Which text box type is better, and why does one show on all of the .cshtml pages, and the other only on one?


  <div style="padding-left:19px; width:806px;">
        @Html.TextBox("PartialTextBox", "", new { style ="width: 100px;", id="partialBox" })

        <input type="text" name="customer" id="newCust" value="">
    </div>
0
Comment
Question by:brgdotnet
2 Comments
 
LVL 1

Accepted Solution

by:
Reece Cottam earned 500 total points
ID: 41764628
Well essentially your @Html.Textbox is a helper method; I.E, a piece of Razor code which dynamically generates your HTML on the server and then puts it onto a cshtml file for you, the other piece of code you have is just bog standard HTML and works in precisely the same way, if you prefer the Syntax of a helper method then by all means go ahead with that, otherwise use raw HTML :)

As for why the plain HTML is on every single view and @html.Textbox is only present on your partial view presumably is down to the fact that MVC knows which namespace your helper method is in , and so it will render it as part of a partial view, it doesn't know what to do with your plain HTML so it just renders it.
1
 
LVL 2

Author Closing Comment

by:brgdotnet
ID: 41764741
Pretty awesome answer. Thanks.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 157
Help with error message for ReportViewer in VS2015 4 42
Getfiles in vb.net 28 42
asp.net mvc input file 2 32
IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now