Anan Srivastava

Anan Srivastava

  • NA
  • 27
  • 1.3k

Return value from function to ActionMethod in controller

Jul 20 2018 2:13 AM
  1. [HttpPost]  
  2.         public ActionResult AddVolunteer(VolunteerInfo viewModel)  
  3.         {  
  4.             if (!ModelState.IsValid)  
  5.             {  
  6.                 return View("AddVolunteer", viewModel);  
  7.             }  
  8.   
  9.             var volunteer = new VolunteerInfo()  
  10.             {  
  11.                 Name = viewModel.Name,  
  12.                 DonationForWhom = DonationValue() //Here's the error. Expecting a parameter  
  13.   
  14.             };  
  15.   
  16.   
  17.             _context.VolunteerInfos.Add(volunteer);  
  18.             _context.SaveChanges();  
  19.             return RedirectToAction("Index""Home");  
  20.   
  21.         }  
  22.   
  23.   
  24.   
  25.         public string DonationValue(string name)  
  26.         {  
  27.             return name; //not sure how to pass this above  
  28.         } 
The error is in the 12th line: There is no argument given that corresponds to the required formal parameter 'name' of 'VolunteerInfoController.DonationValue(string)' VMS.
 
I don't know how to correct this. Please help me

Answers (14)