ViewBag Dropdown List change to textbox

Jan 19, 2012 at 2:16 AM
Edited Jan 19, 2012 at 2:20 AM

Hi Everyone,

 

I want to ask some questions about HTML Helpers to display the Drop Downs in the Create View.So here's the question, How can i change the dropdown list to textbox in the VIEW, because  I want only to type and I don't want to use the dropdown.

CONTROLLER

public ActionResult Create()
{
 ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name");
 
return View();
}

VIEW

<div class="editor-label">
 @Html.LabelFor(model => model.GenreId, "Genre")
</div>
<div class="editor-field">
 @Html.DropDownList("GenreId", String.Empty)

@Html.ValidationMessageFor(model => model.GenreId)

Jan 24, 2012 at 4:46 AM

I'm not a pro, but try taking off  ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name");

and instead of @Html.DropDownList use @Html.TextboxFor


Try skipping the part where Jon implements the genre and variety dropdownlist 

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-5

Coordinator
Jan 24, 2012 at 8:51 AM
Thanks, @kaneXtreme, that's the general idea. You can use @Html.TextBoxFor(model => model.Genre.Name) to just display a simple textbox. However, you'd also need to modify the controller action code to look up the GenreId based on the Genre name that's passed in.

On Monday, January 23, 2012, kaneXtreme wrote:

From: kaneXtreme

I'm not a pro, but try taking off ViewBag.GenreId = new SelectList(db.Genres, "GenreId", "Name");

and instead of @Html.DropDownList use @Html.TextboxFor


Try skipping the part where Jon implements the genre and variety dropdownlist

http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-5

Read the full discussion online.

To add a post to this discussion, reply to this email (mvcmusicstore@discussions.codeplex.com)

To start a new discussion for this project, email mvcmusicstore@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com