Tag: asp.net mvc partialview

MVC将PartialViewResult渲染为字符串

免责声明:我编辑了这个问题,因为我改变了这个过程,但它没有改变任何问题…… 我试图将PartialViewResult渲染为字符串,我试图使用此问题的RenderRazorViewToString方法将视图渲染为字符串 …,我从此qustion mvc返回局部视图的提示作为json 我的问题是,字符串看起来像这样: SomeHeader <table class=”table table-striped”> <tbody data-bind=”template: { name: ‘eventTemplate’, foreach: events }”> 而不是这个 SomeHeader 更新: 该过程如下所示: public ActionResult Index(string item, long id) { var cont = SomePartialView(item, id); return View(model: RenderRazorViewToString(cont)); } 现在View只是渲染字符串,如下所示: @Model RenderRazorViewToString(PartialViewResult)返回这个“残缺”的字符串……

可空的bool值列表始终为空

我有部分观点。 在我的部分中,一些属性是可以为空的布尔值。 如果我选中或取消选中该复选框,则在保存此记录时它始终为空。 如果我想要在取消选中时返回false,那么我该怎么办?取消选中时检查是否为true,否则为null? 这是Entity类: public string Description { get; set; } [Required] public string DocType { get; set; } [Display(Name = “User”)] [Required] public int Key { get; set; } [Display(Name = “Path”)] public string Name { get; set; } public bool? ShowFullWidth { get; set; } public List DmFormDefItems { get; set; } […]

将不同的模型传递给局部视图

我试图从视图中将不同的模型传递给局部视图。 我有两个独立的控制器动作,它们和两个不同的视图模型。 但是当我从视图中调用局部视图时,它会给我错误 传递到字典中的模型项的类型为“Application.ViewModels.Model1ViewModel”,但此字典需要“Application.ViewModels.PartialViewModel”类型的模型项。 我这样称呼它: @Html.Partial(“_CreateUniFunctionPartial”) 视图中的模型调用是 @model Application.ViewModels.Model1ViewModel 和部分视图文件中的模型是 @model Application.ViewModels.PartialViewModel 我不知道如何传递局部视图,所以它不会给出这个错误。 编辑 局部视图 @model Application.ViewModels.PartialViewModel @using (Html.BeginForm(“partialview”, “ApplicationDetail”, FormMethod.Post)) { UniFunctionViewModel @Html.ValidationSummary(true) @Html.LabelFor(model => model.detail, new { @class = “control-label col-md-2” }) @Html.TextBoxFor(model => model.detail, new { @placeholder = “Further Information” }) @Html.ValidationMessageFor(model => model.detail) }

将viewbag从动作控制器传递到局部视图

我有一个部分视图的mvc视图。控制器中有一个ActionResult方法,它将返回一个PartialView。 所以,我需要将ViewRag数据从ActionResult方法传递给Partial View。 这是我的控制器 public class PropertyController : BaseController { public ActionResult Index() { return View(); } public ActionResult Step1() { ViewBag.Hello = “Hello”; return PartialView(); } } 在Index.cshtml视图中 @Html.Partial(“Step1”) Step1.cshtml局部视图 @ViewBag.Hello 但这不起作用。 那么,从viewbag获取数据的正确方法是什么。 我想我正在遵循错误的方法。 请指导我。

如何在其视图中刷新部分视图?

我做错了什么人? 这个想法…… 索引视图 @Html.Partial(“PartialView”, Model) 调节器 public ActionResult PartialView() { return PartialView(“PartialView”); } [HttpPost, ValidateInput(false)] public ActionResult POSTPartialView(string param1) { return PartialView(“PartialView”); } PartialView有一个表格。 我第一次进入Index,PartialView工作,但第二次,在POST调用(来自PartialView中的表单)之后,我只能将PartialView渲染出索引。 所以要解决它,我正在做下一个: [HttpPost, ValidateInput(false)] public ActionResult POSTPartialView(string param1) { return View(“Index”); } 这样可行。 我再次渲染所有索引(在POST后我的更改)。 但我刷新所有页面,所以我丢失了一些CSS元素(例如手风琴折叠)。 我应该使用Ajax只刷新内容PartialView的div吗? 谢谢Mates。 编辑: @using (Html.BeginForm(“PartialView”, “Controller”, FormMethod.Post, new { @class = “form-inline”, role = “form” })) […]

ASP.NET Web API部分响应Json序列化

我正在实现支持部分响应的Web API。 /api/users?fields=id,name,age 鉴于用户类 [JsonObject(MemberSerialization.OptIn)] public partial class User { [JsonProperty] public int id { get; set; } [JsonProperty] public string firstname { get; set; } [JsonProperty] public string lastname { get; set; } [JsonProperty] public string name { get { return firstname + ” ” + lastname; } } [JsonProperty] public int age { […]

在局部视图中使用分页,asp.net mvc

如果有人可以提供以下建议,我将不胜感激:在我的视图中,我显示了项目列表: @model PagedList.IPagedList @using PagedList.Mvc; @foreach (var item in Model) {//displaying data} 我的寻呼机看起来像这样: @Html.PagedListPager(Model, page => Url.Action(“Index”, new { humanID = ViewBag.HumanID, page = page }), new PagedListRenderOptions { LinkToFirstPageFormat = “<>”, }) 问题是当我点击下一页时,它返回空白,没有我的_Layout 。 我不想一直重装_Layout。 有没有办法使用Ajax.ActionLink的寻呼机? 这样我可以在部分视图中UpdateTargedId ?

ASP MVC在部分视图中定义部分

正如标题所述,我想在局部视图中定义一个部分。 我测试过的代码如下: 控制器: public ActionResult Test() { return View(); } public ActionResult PartialTest() { return PartialView(“_PartialTest”); } Test.cshtml: @{ ViewBag.Title = “Test”; } Test @Html.Action(“PartialTest”) _PartialTest.cshtml: partial Test @section scripts { $(document).ready(function() { alert(“Test”); }); } 将部分scripts放在Test.cshtml中可以正常工作,因此问题不在布局中。 有人知道怎么做吗?