簡體   English   中英

單擊按鈕時,MVC將文本框從一個視圖填充到另一個視圖

[英]MVC populate textbox from one view to another view on button click

美好的一天。 我去過很多論壇,但仍然無法掌握解決方案。 系統具有此代碼,其中用戶單擊一個文本框,然后將出現一個包含表的新“ _blank”。 當用戶單擊該表中的“選擇”時,頁面將關閉,並且所選用戶的ID將傳遞到父頁面。 我怎樣才能做到這一點? 我嘗試了在某些論壇中找到的某些腳本,但似乎不起作用。

這是我到子頁面的代碼:

<table class="table table-hover">
 <tr>
 <th>@Html.DisplayNameFor(model => model.First().ID)</th>
 <th>@Html.DisplayNameFor(model => model.First().Fullname)</th>
 <th>@Html.DisplayNameFor(model => model.First().Address)</th>
 </tr>

 @foreach (var item in Model){
 <tr>
 <td>@Html.DisplayFor(modelItem => item.ID)</td>
 <td>@Html.DisplayFor(modelItem => item.Fullname)</td>
 <td>@Html.DisplayFor(modelItem => item.Address)</td>
 <td>
 <a href="@Url.Action("Close", new { ID = item.ID })" class="btn btn-warning" id="close" > Create <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
 </a>
 </td>
 </tr>
 }</table>

 @Html.PagedListPager(Model, page => Url.Action("Showw", new { page, searchString = Request.QueryString["searchString"] }), new PagedListRenderOptions() { Display = PagedListDisplayMode.IfNeeded })

@section Scripts{
<script type="text/javascript">
$("#close").click(function () {
var myWindow = window.open("", "_self");
myWindow.document.write("");
setTimeout(function () { myWindow.close(); }, 1000);
});
</script>
}

我有一個代碼可以檢索ID,但是似乎無法找到適合的代碼,只要this(子頁面)關閉,就可以將其傳輸到父頁面。 再次感謝

確實,打開一個新的空白頁,您可以打開一個引導模型

 <!-- Trigger the modal with a button -->
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>   

@Html.TextBox("displayVal","",new { id= "displayVal" })>    

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Modal Header</h4>
            </div>
            <div class="modal-body">
                <table border="1">
                    <tr  data-dismiss="modal" class="val" data-val="001">
                        <td>001</td>
                        <td>One</td>
                    </tr>
                    <tr  data-dismiss="modal" class="val" data-val="002">
                        <td>002</td>
                        <td>Two</td>
                    </tr>
                    <tr  data-dismiss="modal" class="val" data-val="003">
                        <td>003</td>
                        <td>Three</td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

<script  type="text/javascript">
    $(function () {
        $(".val").click(function () {
           $("#displayVal").val($(this).data("val"));
        });
    });
</script>

當用戶單擊表行時,它將顯示/將值傳遞到父頁面

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM