动作通过列表使用部分视图重复调用

时间:2016-08-26 21:12:24

标签: c# asp.net-mvc asp.net-mvc-5 partial-views

我有简历列表,求职者可以在其中添加注释并向每个人发送消息。所以我创建了简历的部分视图。我在部分视图中使用了Ajax.Beginform方法。在局部视图上有提交选项。现在,当我调用特定的简历部分视图时,它会调用操作并执行作业,但不会为每个简历项重复一次。那为什么反复调用这个动作呢?我的观点在这里

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

这是行动方法

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");
}

我在这样的serchresume视图中调用它

Foreach(简历中的var项目) {

@Html.Partial("Addnote");

} 附上图像以确切包含我想要的内容

enter image description here

0 个答案:

没有答案