Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

mvc, assign value to textbox

Posted on 2013-11-14
2
Medium Priority
?
2,423 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
Suggested Courses

972 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