/Home/Index에 표시되는 Search.cshtml이라는 부분 뷰가 있습니다. 이 파일에는 검색 결과와 함께/Views/Accounts/Index를 검색하고 끌어 오는 HTML 양식이 있습니다. 그 결과를 검색보기에있는 모달 팝업 div에 표시하려고합니다.모달 팝업에서 부분보기 표시
아래 코드에서 Search (sumbit 입력)를 클릭하면 빈 모달이됩니다.
MVC에 관해서는 아직 초보자입니다. Stack Overflow에서 찾은 몇 가지 다른 결과를 시도했지만 해상도를 찾을 수 없었습니다. 아래 코드는 적어도 공백이지만 모달 팝업을 제공합니다.
나는 미친 듯이 뭔가를 놓치고 있습니까? 아래 모달 - 몸 (Html.Action, RenderAction, 부분, RenderPartial) 모든 것을 시도하고 아무것도 작동하는 것. 또한 나는 거기에 잘못된 나무를 짖고 있습니까?
아래에 몇 개의 스크린 샷과 코드가 있습니다. 이 점을 이해하는 데 도움이 될만한 사항이 있으면 감사하겠습니다. 고맙습니다.
/Home/Index with Search partial view
Search.cshtml
@model CustomerRelationshipManager.Models.Search
@{ViewBag.Title = "Search";}
@using (Html.BeginForm("Index", "Accounts", new { id = "searchForm" }))
{
<div style="border: solid 1px #ccc; padding: 30px 0 30px 30px; border-radius: 5px;
width: 325px; margin: auto; display: table;">
<table>
<tr>
<td valign="top">
Search By:
</td>
<td>
@Html.DropDownList("Search_Type", "Search_Type")
</td>
</tr>
<tr>
<td valign="top"></td>
<td>
@Html.TextBox("Search_String")
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" data-toggle="modal" data-target="#myModal" value="Search" />
</td>
</tr>
</table>
</div>
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Modal title</h4>
</div>
<div class="modal-body">
@{Html.Action("Index","Accounts");}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
}
HomeController.cs
public ActionResult Search()
{
List<SelectListItem> items = new List<SelectListItem>();
items.Add(new SelectListItem() { Text = "Account Number", Value = "Account_ID" });
items.Add(new SelectListItem() { Text = "Last Name", Value = "Last_Name" });
items.Add(new SelectListItem() { Text = "Phone Number", Value = "Phone_Number" });
ViewBag.Search_Type = items;
return PartialView();
}
[HttpPost]
[AllowAnonymous]
public ActionResult Search(Search search)
{
return PartialView("~/Accounts/Index");
//return RedirectToAction("Index", "Accounts");
}
AccountController.cs는
@model IEnumerable<CustomerRelationshipManager.Models.Account>
@{
ViewBag.Title = "Home";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>Account #</th>
<th>Contact Name(s)</th>
<th>Address</th>
<th>Contact</th>
</tr>
w2
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Account_ID)
<span> </span>
</td>
<td>
@foreach (var i in item.Account_Person)
{
<span>
<b>@Html.DisplayFor(x => i.Person_Type.Name)</b>
<br />
@Html.DisplayFor(x => i.Person.First_Name)
@Html.DisplayFor(x => i.Person.Last_Name)
</span>
<br />
}
</td>
<td>
@foreach (var i in item.Account_Address)
{
<span>
<b>@Html.DisplayFor(x => i.Address_Type.Name)</b>
<br />
@Html.DisplayFor(x => i.Address.Address1)
<br />
@Html.DisplayFor(x => i.Address.Address2)
@if (i.Address.Address2 != null)
{ <br />}
@Html.DisplayFor(x => i.Address.City)
@Html.DisplayFor(x => i.Address.State)
@Html.DisplayFor(x => i.Address.Postal_Code)
<br />
@Html.DisplayFor(x => i.Address.Country)
<br />
</span>
}
</td>
<td>
@foreach (var i in item.Account_Contact)
{
<span>
<b>@Html.DisplayFor(x => i.Contact.Contact_Type.Name)</b>
<br />
@Html.DisplayFor(x => i.Contact.Value)
<br />
</span>
}
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.Account_ID }) |
@Html.ActionLink("Details", "Details", new { id = item.Account_ID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.Account_ID })
</td>
</tr>
}
제출 버튼이 양식 태그 안에 있으면 양식 제출을 클릭하여 제출하십시오. 부분 뷰 결과를 얻고 모달 내용을 업데이트하려면 action 메소드에 대한 ajax 호출을 작성해야합니다. – Shyju