Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have list of resumes on which jobseeker can "add note" and "send message" to each of them. So I created partial view of resume. I used Ajax.Beginform method in partial views. On partial view there is submit button. Now when I call a specific resume partial view submit option it calls the action and perform the job but not single time it repeats for each resume item i.e. action repeatedly call. So why is the action called repeatedly?


I am calling partial views as


HTML
@model NoteViewModel
<script src="~/Content/scripts/jquery-2.1.3.min.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<div class="app-tab-content" id="two-1">

    @using (Ajax.BeginForm("AddNote","Employer",new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "result" }))
    { 
        if(@Model!=null)
        { 
        <input type="text" name="note" />
        <input type="hidden" value="@Model.Res_id" name="res" />
        <input type="hidden" value="@Model.Job_id" name="job" />

        @*<button type="submit" value="AddNote"></button>*@

        <input type="submit" id="AddNote" value="Add Note" />
        }
    }
    <div id="result">
       @if(ViewBag.NoteMessage!=null)
       { 
         <p>ViewBag.NoteMessage</p>
       }
    </div>
</div>  






My action which is repeatedly calling is

C#
public ActionResult AddNote(string note, int? res, int? job)
{
    jpc_resume_job jr = db.jpc_resume_job.Where(m => m.job_id == job && m.resume_id == res).FirstOrDefault();

    if (ModelState.IsValid)
    {

        jr.note = note;
        db.Entry(jr).State = EntityState.Modified;
        db.SaveChanges();
        ViewBag.NoteMessage = "Note Added Successfully";
        return PartialView("Addnote");
    }
    ViewBag.NoteMessage = "Note Not Added Successfully";
    return PartialView("Addnote");
}





Foreach(var item in resume) {

@Html.Partial("Addnote");
}


What I have tried:

I have tried the above code its working but i want to call just once not repeatedly
Posted
Comments
Halit Yurttaş 27-Aug-16 20:23pm    
Where are you declare or assign resume?
mirzabari 28-Aug-16 4:59am    
in lowest part of my code ,i.e. in searchresume view where i am binding list of resume

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900