Solved

Types of HTML text boxes when using MVC with .Net

Posted on 2016-08-21
2
33 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

15 Experts available now in Live!

Get 1:1 Help Now