41 lines
732 B
Plaintext
41 lines
732 B
Plaintext
![]() |
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[]
|