Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 473.7k

How to pass reference by object in asp.net mvc?

Sep 9 2020 3:16 AM
Hi Team
 
I have a method, but i want to pass reference byy object, meaning i have declared it as a string, but when i insert raw data it stored to the db, that is not what i want. I want when a user insert any object name it must store it to the record.
  1.    [Route("Home/AllCourses")]  
  2.         public ActionResult CoursesRegistration(RegCoursesViewModel eNtsaRegistration)  
  3.         {  
  4.             string courseName = "TestData"// This stores to the db.  
  5. string courseName = string.empty; // This is not stored to the record  
  6.             eNtsaRegistration.Courses = new eNtsaCourses();  
  7.             if (ModelState.IsValid)  
  8.             {  
  9.   
  10.                 eNtsaRegistration.Courses.Course = courseName;  
  11.                 eNtsaRegistration.Courses.Id = Guid.NewGuid();  
  12.                 cb.Courses.Add(eNtsaRegistration.Courses);  
  13.                 cb.SaveChanges();  
  14.             }  
  15.   
  16.             return RedirectToAction("AllCourses");  
  17.         }  
 

Answers (7)