Solved

Types of HTML text boxes when using MVC with .Net

Posted on 2016-08-21
2
43 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

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

Suggested Solutions

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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