Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 473.4k

Server Error/Application problem?

Aug 20 2020 6:32 AM
Hi Team
 
I have a routing problem, i have configured my routing well, but some how i am encountering a problem. This is my logic below;
  1. // Route to CoursesRegistered    
  2. routes.MapRoute(    
  3.     name:"CoursesRegistration",    
  4.     url:"courses-enrolled-for/",    
  5.     defaults: new {controller="Home", action = "CoursesRegistration", url = UrlParameter.Optional}    
  6.   
  7. );    
  8.   
  9. [HttpPost]    
  10.  public ActionResult CoursesRegistration( eNtsaRegCourses model)    
  11.  {    
  12.        if(ModelState.IsValid)    
  13.        {    
  14.            try    
  15.            {    
  16.                cb.SaveChanges();    
  17.                return Json(new { success = true });    
  18.            }catch(Exception ex)    
  19.            {    
  20.                ModelState.AddModelError("", ex.Message);    
  21.            }    
  22.        }       
  23.        return PartialView("CoursesRegistration", model);    
  24.  }  
  25.  // saving changes here.    
  26.  static void SaveChanges(eNtsaCourses model)    
  27.  {  
  28.  }    
  1. @using (Html.BeginForm("CreateCoursesRegistration""Home", FormMethod.Post, new { id = "createCourseForm", @class = "form-horizontal" }))    
  2. {    
  3.     <div class="modal-footer">    
  4.         <button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>    
  5.         <a href="@Url.Action("CoursesRegistration", "Home")" class="btn btn-large btn-success", onclick="$('#exampleModal').modal('show')">Create Courses</a>    
  6.         <script type="text/javascript">    
  7.             function createCourses() {    
  8.                 $.ajax({    
  9.                     url: "/Home/CoursesRegistration",    
  10.                     data: $('#createCourseForm').serialize(),    
  11.                     type: 'post',    
  12.                     success: function (data) {    
  13.                     if (data.Success)                                                 
  14.                         $("#exampleModal").modal('hide');    
  15.                     } else {    
  16.                     }   
  17.                 },    
  18.                 error: function (xhr, status) {    
  19.                 }                                           
  20.                 });    
  21.                 return false;    
  22.                 }   
  23.         </script>  
  24.     </div>    
  25. }

Answers (3)