Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 614918c

Browse files
Create dropdown list using SelectList
1 parent 49fb09a commit 614918c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Controllers/BookController.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.AspNetCore.Mvc.Rendering;
67
using Webgentle.BookStore.Models;
78
using Webgentle.BookStore.Repository;
89

@@ -44,6 +45,8 @@ public ViewResult AddNewBook(bool isSuccess = false, int bookId = 0)
4445
Language = "English"
4546
};
4647

48+
ViewBag.Language = new SelectList(new List<string>() { "Hindi", "English", "Dutch"});
49+
4750
ViewBag.IsSuccess = isSuccess;
4851
ViewBag.BookId = bookId;
4952
return View(model);
@@ -61,6 +64,8 @@ public async Task<IActionResult> AddNewBook(BookModel bookModel)
6164
}
6265
}
6366

67+
ViewBag.Language = new SelectList(new List<string>() { "Hindi", "English", "Dutch" });
68+
6469
ModelState.AddModelError("", "This is my custom error message");
6570
ModelState.AddModelError("", "This is my second custom error message");
6671

‎Webgentle.BookStore/Webgentle.BookStore/Views/Book/AddNewBook.cshtml‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,8 @@
2121

2222
<div class="form-group">
2323
<label asp-for="Language" class="control-label"></label>
24-
<select asp-for="Language" class="form-control">
25-
<option value="">Please choose book language</option>
26-
<option value="Hindi">Hindi (One of the best language)</option>
27-
<option value="English">English (Global language)</option>
28-
<option value="Dutch">Dutch (My cutom message)</option>
24+
<select asp-for="Language" class="form-control" asp-items="ViewBag.Language">
25+
<option value="">Please choose your language</option>
2926
</select>
3027
<span asp-validation-for="Language" class="text-danger"></span>
3128
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /