在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Model: public class TestModel { [Required] public string Id { get; set; } } Controller: public class TestController : Controller { // GET: Test public ActionResult Index() { ViewData["Name"] = "NULL"; return View(); } [HttpPost] public ActionResult TestRefresh() { var list = new List<TestModel>() { new TestModel { Id = "1" }, new TestModel { Id = "2" } }; return PartialView("PartialInput", list); } } View: @{ ViewBag.Title = "Index"; } <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function () { $("#btRefresh").click(function () { $.ajax({ type: "POST", url: "/Test/TestRefresh",// Controller名(TestController)/Method" success: function (data) { $("#TestDiv").html(data);// Partial View中的div }, error: function (msg) { alert('error:' + msg); } }); }); }); </script> <body> @{ <div> @{ Html.RenderPartial("PartialInput"); } </div> <input type="text" id="textRefresh"> <input type="submit" id="btRefresh" value="Refresh"> } </body> Partial View: @model List<partialview.Models.TestModel> <style> .green-background { background-color: yellow; } </style> <div id="TestDiv" class="green-background"> @{ if (Model == null) { return; } } @foreach (var item in Model) { <ul> <li>@item.Id</li> </ul> } </div> 演示:
|
请发表评论