Solved

mvc, assign value to textbox

Posted on 2013-11-14
2
2,225 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
[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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

751 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