I'm trying to update a form in my application using Ajax.BeginForm. The updation is taking place but after executing the function in the controller it redirects to a view with the controller function name. I don't want it to redirect to another view instead I want to display an alert message like success or failure.

<div id="target" ondrop="drop(event)" ondragover="allowDrop(event)">
   @using (Ajax.BeginForm("Insert", "User", new AjaxOptions{
       HttpMethod = "POST",
       UpdateTargetId = "target",
       OnSuccess = "success"
   }))
   {
       <ul>
       @foreach (var item2 in Model.sample)
       {
           <li draggable="true" ondragstart="drag(event)" class="Contentpropclass" value="@item2.name">
               <input type="hidden" id="ID" name="ID" value="@item2.id"/>
               <input type="hidden" value="@item2.name" name="Name" id="Name"/>
               @item2.name
               <input type="number" name="age"  value="@item2.age" placeholder="age"  />
               <input type="number" name="siblings" value="@item2.siblings" placeholder="" /> 
           </li>     
       }
       </ul>
       <br /> <br /> <br />
       <br /> <br /> <br />
       <br /> <br /> <br />

       <button type="submit" value="submit">Save</button>
    }
</div>   

Related posts

Recent Viewed