rspec/rules/S5770/csharp/rule.adoc

41 lines
732 B
Plaintext
Raw Normal View History

2020-06-30 12:50:28 +02:00
include::../description.adoc[]
== Noncompliant Code Example
----
using System.Web.Mvc;
public class HomeController : Controller
{
public ActionResult Article()
{
ViewBag.Title = "Title"; // Noncompliant, model should be used
ViewData["Text"] = "Text"; // Noncompliant, model should be used
return View();
}
}
----
== Compliant Solution
----
using System.Web.Mvc;
public class ArticleModel
{
public string Title { get; set; }
public string Text { get; set; }
}
public class HomeController : Controller
{
public ActionResult Article()
{
var model = new ArticleModel { Title = "Title", Text = "Text" };
return View(model);
}
}
----
include::../see.adoc[]