C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,319 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I getting this as a error, I get it??? this is in the controller.
public class CorvetteCostController : Controller
{
private const double V = 99.00;
// GET: CorvetteCostController
public ActionResult GetIndex()
{
return View();
}
public IActionResult Index
{
get
{
var model = new List<CorvetteCost>()
{
new CorvetteCost{ CorvetteId = 1, CorvetteItem = "Filter", CorvetteItemCost = "$99.00", CorvetteStore = "Corvette Mods", Date = "3/3/2021", Maintance = "No", OrginalCost = (float)V, Repair = "yes", Upgrade = "no" }
//new MyModel{ CorvetteId=1,CorvetteItem="aa"},
// new MyModel{ CorvetteId=2,CorvetteItem="bb"}
};
return View(model);
}
}
// GET: CorvetteCostController/Details/5
public ActionResult Details(int id)
{
return View();
}
// GET: CorvetteCostController/Create
public ActionResult Create()
{
return View();
}
// POST: CorvetteCostController/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(IFormCollection collection)
{
try
{
return RedirectToAction(nameof(GetIndex())); //GetIndex is the error
}
catch
{
return View();
}
}
// GET: CorvetteCostController/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: CorvetteCostController/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
if (collection is null)
{
throw new ArgumentNullException(nameof(collection));
}
try
{
return RedirectToAction(nameof(GetIndex())); //GetIndex is the error
}
catch
{
return View();
}
}
// GET: CorvetteCostController/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: CorvetteCostController/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
return NewMethod();
}
catch
{
return View();
}
ActionResult NewMethod()
{
return RedirectToAction(nameof(GetIndex())); //GetIndex is the error
}
}
}
}
nameof
requires an identifier. You are trying to call the function GetIndex()
and whatever that returns (the expression) would then be passed to nameof
. nameof
is a compile time expression and just needs the identifier name.
return RedirectToAction(nameof(GetIndex)); // => RedirectToAction("GetIndex")