亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在ASP.NET MVC中單擊按鈕時呈現部分視圖

在ASP.NET MVC中單擊按鈕時呈現部分視圖

MM們 2019-08-08 16:32:05
在ASP.NET MVC中單擊按鈕時呈現部分視圖我在Visual Studio中創建了一個新的ASP.NET MVC 5應用程序。然后,我定義了兩個模型類:public class SearchCriterionModel{   public string Keyword { get; set; }}public class SearchResultModel{   public int Id { get; set; }   public string FirstName { get; set; }   public string Surname { get; set; }}然后我創建了SearchController如下:public class SearchController : Controller{   public ActionResult Index()   {     return View();   }   public ActionResult DisplaySearchResults()   {     var model = new List<SearchResultModel>     {       new SearchResultModel { Id=1, FirstName="Peter", Surname="Pan" },       new SearchResultModel { Id=2, FirstName="Jane", Surname="Doe" }     };     return PartialView("SearchResults", model);   }}以及視圖Index.cshtml(強烈鍵入SearchCriterionModel模型和模板編輯)和SearchResults.cshtml作為類型模型(模板列表)的局部視圖。IEnumerable<SearchResultModel>這是索引視圖:@model WebApplication1.Models.SearchCriterionModel@{   ViewBag.Title = "Index";}@using (Html.BeginForm()){   @Html.AntiForgeryToken()   <div class="form-horizontal">     <h4>SearchCriterionModel</h4>     <hr />     @Html.ValidationSummary(true, "", new { @class = "text-danger" })     <div class="form-group">       @Html.LabelFor(model => model.Keyword, htmlAttributes: new { @class = "control-label col-md-2" })       <div class="col-md-10">         @Html.EditorFor(model => model.Keyword, new { htmlAttributes = new { @class = "form-control" } })         @Html.ValidationMessageFor(model => model.Keyword, "", new { @class = "text-danger" })       </div>     </div>正如你所看到的,我加了一個div與id="searchResults"標準模板下方和編輯按鈕。我要的是顯示局部視圖SearchResults.cshtml的div底部,但點擊按鈕之后。我已成功通過使用顯示局部視圖@Html.Partial("SearchResults", ViewBag.MyData),但是在第一次加載父視圖時我將其呈現并且我已經ViewBag.MyData在Index()方法中設置了,這不是我想要的
查看完整描述

2 回答

?
料青山看我應如是

TA貢獻1772條經驗 獲得超8個贊

所以這是控制器代碼。

public IActionResult AddURLTest(){
    return ViewComponent("AddURL");}

您可以使用JQuery加載方法加載它。

$(document).ready (function(){
    $("#LoadSignIn").click(function(){
        $('#UserControl').load("/Home/AddURLTest");
    });});

代碼鏈接


查看完整回答
反對 回復 2019-08-08
  • 2 回答
  • 0 關注
  • 1253 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號