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
@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
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