Solved

mvc, assign value to textbox

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

856 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