Solved

mvc, assign value to textbox

Posted on 2013-11-14
2
2,075 Views
Last Modified: 2013-11-14
@Html.TextBoxFor(m = > m.typeID)

and I want to add value there. like <input type="text" value="100">

how can I do that in mvc razor?
0
Comment
Question by:solution1368
2 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 500 total points
ID: 39648712
You can do this on the page, just google "mvc textboxfor set value".

However, the proper way to do this would be to set the default value on your model before you pass it to the view.

To expand a little. You should set the default value in the constructor of your model, then instantiate that model and pass it to the view. ie,

In your controller:
public ViewResult Create()
{
  // Loads default values
  MyModel m = new MyModel();
  return View("Create", m);
}

Open in new window


Hope this helps,
Dustin
0
 

Author Closing Comment

by:solution1368
ID: 39648779
Thank. I chose the short cut solution { @value = "SomeThing" } and it works fine. Thanks

and I have more questions if you have time.http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_28294352.html
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

Suggested Solutions

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

760 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