使用页眉

时间:2017-09-27 12:38:16

标签: c# jquery asp.net-mvc bootstrap-modal

我正试图弹出bootstrap。在我的“NoteListPartial.cshtml”页面中;如果我点击编辑按钮,我想要弹出“Not.cshtml”打开。但是当我点击按钮弹出窗口出现但我的标题也出现了弹出窗口,但我不希望它出现。

1-我在Detail.cshtml页面上调用NoteListPartial.cshtml页面。

2-我的Detail.cshtml代码如下:

<div class="NoteList">

</div

<script>
    var projectid = @Model.ID;
    $.ajax({
        method: "get",
        url: '@Url.Action("NoteListPartial", "Project")',
        data: {projectid:projectid},
        success: function(returningdata){
            $("div.NoteList").html(returningdata);
        }
    });
</script>

3-我的NoteListPartial.cshtml代码如下:

@foreach (var item in Model)
{
    <div class="item">
        <div class="item-head">
            <div class="item-details">
                <a class="item-name primary-link">@item.Name</a>
                span class="item-status">
                    <a href="@Url.Action("Note", "Project", new { ID = item.ID, ProjectID = item.ProjectID })" data-target="#NoteDetailModal" data-toggle="modal">EDIT</a>
                    <a href="@Url.Action("NoteDelete", "Project",new { ID=item.ID, ProjectID=item.ProjectID})">Delete</a>
                </span>
            </div>
        </div>
        <div class="item-body"> @item.Content </div>
    </div>
}

<div class="modal fade" id="NoteDetailModal" tabindex="-1" role="dialog" aria-labelledby="">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <!-- Content comes here. This code continues at Note.cshtml -->
        </div>
    </div>
</div>

4-我的Note.cshtml代码如下,我希望弹出“Not.cshtml”

<!-- Continuation of modal on page NoteListPartial.cshtml -->

<div class="modal-header">
    <button type="button" class="close" data-dissmiss="modal" aria-label="Close"><span aria-hidden="true">x</span></button>
    <h4 class="modal-title" id="myModalLabel">Edit Note</h4>
</div>
<form method="post" role="form">
    <div class="modal-body">
        <div class="form-group">
            <label>Title:</label>
            <input type="text" name="Name" value="@Model.Name" />
        </div>
        <div class="form-group">
            <label>Content:</label>
            <textarea name="Content">@Model.Content</textarea>
        </div>
    </div>
    <div class="modal-footer">
        <input type="submit" class="btn btn-default" value="Update" />
    </div>
</form>

当我运行项目并单击Detail.cshtml中的编辑按钮时,弹出窗口正在打开但我遇到这样的屏幕: enter image description here

ProjectController.cs:

public ActionResult NoteListPartial(RaporModel Filter, int? ProjectID)
{
    IEnumerable<tbl_ProjectNote> prjnote = Sabitler.Note.Where(d => d.ProjectID == ProjectID).OrderByDescending(d => d.ID);
    int PageNo = Convert.ToInt32(Request.QueryString["Page"] ?? "1");
    int totalnumber = prjnote.Count();
    prjnote = prjnote.Skip((PageNo - 1) * Filter.SBGS).Take(Filter.SBGS);
    ViewBag.Pagination = Functions.PageToGet(PageNo, totalnumber, Filter.SBGS, "", "active");
    return PartialView(prjnote.ToList());
}

public ActionResult Note(RaporModel Filter, int? ID)
{
var prjnote = db.tbl_ProjectNot.FirstOrDefault(d => d.ID == ID);
if (prjnote == null)
    prjnote = new tbl_ProjectNot();
    return View(prjnote);
}

[HttpPost]
public ActionResult Note(tbl_ProjectNote prjnote)
{
    if (prjnote.Name == null)
    {
        BilgiMesaji(Tur.Warn, "Note title can't null!");
        return RedirectToAction("Note", new { ProjectID = prjnote.ProjectID });
    }
    if (!string.IsNullOrEmpty(prjnote.Name) && prjnote.Name.Length > 100)
    {
        BilgiMesaji(Tur.Warn, "Note title can not be more than 100 characters!");
        return RedirectToAction("Note", new { ProjectID = prjnote.ProjectID });
    }
    if (!string.IsNullOrEmpty(prjnote.Content) && prjnote.Content.Length > 500)
    {
        BilgiMesaji(Tur.Warn, "Note content can not be more than 500 characters!");
        return RedirectToAction("Note", new { ProjectID = prjnote.ProjectID });
    }

    var prjnoteDB = db.tbl_ProjectNote.FirstOrDefault(d => d.ID == prjnote.ID);

    if (prjnoteDB == null)
        prjnoteDB = new tbl_ProjectNot();

        prjnoteDB.Name = prjnote.Name;
        prjnoteDB.Content = prjnote.Content;
        prjnoteDB.ProjectID = prjnote.ProjectID;
        if (prjnoteDB.ID == 0)
        {
            prjnoteDB.UserID = us.ID;
            prjnoteDB.AddDate = DateTime.Now;
            db.tbl_ProjectNot.Add(prjnoteDB);
        }
        db.SaveChanges();

        Sabitler.Note = db.tbl_ProjectNot.ToList();

        BilgiMesaji(Tur.Success, "Recording successfully added!");

        return RedirectToAction("Note", new { ProjectID = prjnote.ProjecID });
}

1 个答案:

答案 0 :(得分:2)

您需要使用public ActionResult Note(RaporModel Filter, int? ID)操作中的PartialView而不是View返回

public ActionResult Note(RaporModel Filter, int? ID)
{
    var prjnote = db.tbl_ProjectNot.FirstOrDefault(d => d.ID == ID);
    if (prjnote == null)
        prjnote = new tbl_ProjectNot();
    return PartialView(prjnote);
}

返回View()将包含带有标题和导航栏的_layout.cshtml页面。

有关详细信息,请参阅此处: View() vs. PartialView()