Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mvc, assign value to textbox

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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 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)
Suggested Courses

715 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