Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJoe Mackey
20,418 PointsIn IssuesController.cs complete the server-side validation rule that enforces if the issue severity is "Critical" that t
I have no idea what is being ask when it says I need two arguments WHERE TO GO TO READ AND UNDERSTAND THIS?
using System.Web.Mvc;
using IssueReporter.Data;
using IssueReporter.Models;
namespace IssueReporter.Controllers
{
public class IssuesController : Controller
{
private IssuesRepository _issuesRepository;
public IssuesController()
{
_issuesRepository = new IssuesRepository();
}
public ActionResult Index()
{
return View();
}
public ActionResult Report()
{
var issue = new Issue();
SetupDepartmentsSelectListItems();
return View(issue);
}
[HttpPost]
public ActionResult Report(Issue issue)
{
if (issue.Severity == Issue.SeverityLevel.Critical && string.IsNullOrEmpty(issue.Email))
// OK I clearly do not understand overloads. Tje compiler says I require two arguments.
// I thoought "Index" , "Email" were my two arguments. Where to go to read and understand better?
{
ModelState.AddModelError("CustomError", "The item is removed from your cart");
return RedirectToAction("Index", "Email");
}
else
{
ModelState.AddModelError(string.Empty,"The item cannot be removed");
return View("Index");
}
if (ModelState.IsValid)
{
_issuesRepository.AddIssue(issue);
return RedirectToAction("Index");
}
SetupDepartmentsSelectListItems();
return View(issue);
}
private void SetupDepartmentsSelectListItems()
{
ViewBag.DepartmentsSelectListItems = new SelectList(
Data.Data.Departments, "Id", "Name");
}
}
}
1 Answer
Jon Wood
9,884 PointsThis challenge just wants you to add an error to ModelState
. The two arguments it mentions is for the AddModelError
method, one for the key of the error and another for the string for the message. That's all you need for this challenge. :)