TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bouthaina Tlijani
NA
265
22.8k
ASP.NET MVC 5 : System.ArgumentNullException on DropDownList
Jan 3 2018 8:32 AM
Hello everyone, well i'm facing a problem here, i've created an asp.net mvc5 web application and in it i've used a DropDownList , when i trie to create a new module
i receive this exception:'System.ArgumentNullException' occurred in System.Web.Mvc.dll but was not handled in user code
Additional information: Value cannot be null.
This is my controller:
// GET: Module/Create
public ActionResult Create()
{
List
ListAppli = new List
()
{
new SelectListItem() {Text="Tablette", Value="Tablette"},
new SelectListItem() {Text="Mobile", Value="Mobile"},
};
ViewBag.ListAppli = ListAppli;
return View();
}
// POST: Module/Create
[HttpPost]
public ActionResult Create(Module module)
{
if (ModelState.IsValid)
{
db.Modules.Add(module);
db.SaveChanges();
var idManager = new IdentityManager();
var success = idManager.CreateRole(module.libelle+" : "+module.application);
return RedirectToAction("Index");
}
return View(module);
}
//And this is my DropDownList
Application
@Html.DropDownListFor(model => model.application, new SelectList(ViewBag.ListAppli, "Value", "Text"))
//And this is the model
namespace AspNetRoleBasedSecurity.Models
{
public class Module
{
[Key]
public int id { get; set; }
[Required(ErrorMessage = "Le code est requis!")]
[Display(Name = "Code")]
public string code { get; set; }
[Required(ErrorMessage = "Le libellé est requis!")]
[Display(Name = "Libelle")]
public string libelle { get; set; }
[Display(Name = "Application")]
public string application { get; set; }
}
}
//Any idea please :D and thnx ^^
Reply
Answers (
2
)
Showing Source code instead of running the file
Attribute based routing is not working