gpt4 book ai didi

asp.net-mvc - ASP.NET MVC : Partial view not rendering

转载 作者:行者123 更新时间:2023-12-02 03:41:58 25 4
gpt4 key购买 nike

我对 ASP.NET MVC 有点陌生。我面临着一些非常基本的问题,我的部分 View 没有渲染。这是详细信息

我有一个主页和一个部分 View

主页操作看起来像

public ActionResult Index()
{
return View();
}

主索引 View 看起来像

@model Testing.Models.Employee

@{
ViewBag.Title = "Home Page";
}

<div class="row">

</div>

<div class="row">
<div id="formsIndex">
@{
Html.Partial("_TestForm");
}
</div>
</div>

@section scripts {
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
}

这里我以这种方式显示部分 View Html.Partial("_TestForm"); 但没有用于部分 View 的 UI。

部分 View 代码如下

@model Testing.Models.Employee

@using (Ajax.BeginForm("Index", "Home", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "formsIndex" }))
{
@Html.AntiForgeryToken()

<div class="form-horizontal">

@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.City, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.City, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.City, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</div>
}

当我以这种方式将模型传递给部分 View 时 Html.Partial("_TestForm", Model); 然后也没有 UI 出现。

请告诉我哪里出错了?

最佳答案

在方法 return PartialView() 中使用并尝试这个

@Html.Partial("_TestForm");

关于asp.net-mvc - ASP.NET MVC : Partial view not rendering,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48301857/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com