question

BrentHumber-6530 avatar image
0 Votes"
BrentHumber-6530 asked ·

Expression does not have a name CS8081

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
         }
     }
 }

}

dotnet-csharp
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

What is the error ?

0 Votes 0 ·

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered ·

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")


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.