asp.net-mvc-partialview

Render partial view to string MVC4

♀尐吖头ヾ 提交于 2019-11-30 14:29:33
I am using the following to render a partial view to a string... protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (var sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); return sw.GetStringBuilder().ToString(); } } However it

ASP.NET MVC 4 generating a treeview with recursive partial view

六眼飞鱼酱① 提交于 2019-11-30 11:40:47
问题 I have a partial view in an MVC 4 project, which is strongly typed. It takes an IEnumerable collection of a table of a database. In that table there are IDs, Names, and ParentIDs for storing hierarchical connection between records. The view that calls the partial view is also strongly typed, it takes the whole database as the model, and passes the Categories table to the partial view, as an enumerable collection: @Html.Partial("_TreeCategories", @Model.Categories.ToList()) And in the partial

pass a different model to the partial view

若如初见. 提交于 2019-11-30 11:17:03
I am trying to pass a different model to the partial view from a view. I have two separate controller actions for both of them and two different view models. But when I call the partial view from within the view it gives me the error The model item passed into the dictionary is of type 'Application.ViewModels.Model1ViewModel', but this dictionary requires a model item of type 'Application.ViewModels.PartialViewModel'. I am calling it like this: @Html.Partial("_CreateUniFunctionPartial") the model call in the view is @model Application.ViewModels.Model1ViewModel and model in partial view file

ASP.NET Web API partial response Json serialization

非 Y 不嫁゛ 提交于 2019-11-30 07:42:39
问题 I am implementing a Web API that supports partial response. /api/users?fields=id,name,age Given the class User [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 { get; set; } } The Json formatter works great when

ASP.NET MVC 4 generating a treeview with recursive partial view

允我心安 提交于 2019-11-30 00:49:20
I have a partial view in an MVC 4 project, which is strongly typed. It takes an IEnumerable collection of a table of a database. In that table there are IDs, Names, and ParentIDs for storing hierarchical connection between records. The view that calls the partial view is also strongly typed, it takes the whole database as the model, and passes the Categories table to the partial view, as an enumerable collection: @Html.Partial("_TreeCategories", @Model.Categories.ToList()) And in the partial view, I want to take the root nodes first, so I can extend the whole tree in a recursive way. In the

Submit Data from partial view to a controller MVC

我的梦境 提交于 2019-11-29 23:29:46
问题 I have a list of employment records, you can also add an employment record from the same page using a partial view. Heres employment.cshtml that has a partial view for the records list and a partial view to add a new record which appears in a modal pop up. <h2>Employment Records</h2> @{Html.RenderPartial("_employmentlist", Model);} <p> <a href="#regModal" class="btn btn_b" rel="fancyReg">Add New Record</a> </p> <div style="display:none"> <div id="regModal"> @{Html.RenderPartial("

Render partial view to string MVC4

ぃ、小莉子 提交于 2019-11-29 21:16:32
问题 I am using the following to render a partial view to a string... protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (var sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);

Send partial view model and Update partial view with jQuery has issues

℡╲_俬逩灬. 提交于 2019-11-29 15:47:27
I use partial view for small model inside other view model. so i send changes of it by grabbing model data from wrapper form and using serializeArray() . then return PartialViewResult from action and finally fill partial view div container by returned result. this is my code: var modelStr = $("#[wrapperFormName]").serializeArray(); $.ajax({ type: "POST", url: targetUrl, cache: false, data: modelStr, success: function (sucResult) { $('#pa_Cnt').html(sucResult); }, fail: function (result) { alert("Fail"); } }); and render partialview in view as this: @using (Html.BeginForm("[ActionName]", "

ASP.NET MVC 4 Html.BeginForm in Partial View , values after post not right

半世苍凉 提交于 2019-11-29 12:37:47
Main Page -> Section 1 (has some dropdowns and a save button) <div id="tab-section1"> @{Html.RenderPartial("_Section1", Model.Section1);} </div> <div id="tab-section2"> <div id="section2"> @{Html.RenderPartial("_Section2", Model.Section2);} </div> @{Html.RenderPartial("_SubSection2", Model.SubSection2);} </div> The section 1 contents are placed in a partial view with @Html.BeginForm in it. and rendered on main view using @Html.RenderPartial @using MyData @model Section1ViewModel @using(Html.BeginForm("EditSection1", "Project", FormMethod.Post, new { id = "section1-form", name = "section-form"

ASP.net MVC: Execute Razor from DB String?

为君一笑 提交于 2019-11-29 07:17:31
I was thinking about giving end users the ability to drop Partial Views (controls) into the information being stored in the database. Is there a way to execute a string I get from the database as part of the Razor view? Buildstarted Update (I forgot all about this) I had asked this question previously (which lead me to create RazorEngine) Pulling a View from a database rather than a file I know of at least two: RazorEngine , MvcMailer I have a bias towards RazorEngine as it's one that I've worked on but I have a much simpler one at Github called RazorSharp (though it only supports c#) These