?
Solved

Types of HTML text boxes when using MVC with .Net

Posted on 2016-08-21
2
Medium Priority
?
51 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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 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