razor

Consuming WebApi in MVC3

微笑、不失礼 提交于 2019-12-30 01:32:10
问题 Using WebApi, what is the best way to consume a service in a MVC client? If the response comes back as: <?xml version="1.0" encoding="UTF-8"?> <ArrayOfContact xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Contact> <Id>1</Id> <Name>Bilbo Baggins</Name> </Contact> <Contact> <Id>2</Id> <Name>Frodo Baggins</Name> </Contact> </ArrayOfContact> How can I take that, get my Contacts out and list them in a MVC3 Razor View using @Model? There's a

Make ASP.NET MVC 3 Razor View Engine ignore .vbhtml files

不想你离开。 提交于 2019-12-29 17:59:08
问题 How can I remove the VB Razor Engine or configure the RazorViewEngine to not use and look for .vbhtml files on disk? For new ASP.NET MVC 3 Razor projects, I always remove the WebFormViewEngine in Application_Start because I won't ever be using it and so I don't need it to search for .aspx, .ascx or .master files on disk. For this same reason I would like to avoid .vbhtml file searching. 回答1: This is the code for your custom view engine: public class CSRazorViewEngine : RazorViewEngine {

How to relationship tables in groupby and sum row and column and Where (asp-route-id)

别等时光非礼了梦想. 提交于 2019-12-29 09:34:06
问题 First Table is Power Plant Name List Table public class PowerPlants { public int ID { get; set; } [Required] public string PowerPlantName { get; set; } [Required] public string PowerPlantShortName { get; set; } [Required] public string PowerPlantCode { get; set; } public virtual ICollection<REHPViewModelData> REHPData { get; set; } public virtual ICollection<BudgetYearlyAllocation> BudgetYearlyAllocation { get; set; } } Second Table is BudgetYear Table public class BudgetYear { public int ID

Dictionary<short, Dictionary<EnFunction, bool>> model binding not work

删除回忆录丶 提交于 2019-12-29 09:24:08
问题 I could not bind the model to Controller. Please give me any advice. Model,controller and view classes are below. When model is submmited, dictionary property equals to null. public class GroupRights //model { public List<DtoGrup> groups { get; set; } public Dictionary<short, Dictionary<EnFunction, bool>> groupRights { get; set; } // group function HasPermission } public enum EnFunction { LPDU_login, LPDU_changePassword, LPDU_transitList, LPDU_PosEventList, .... } Controller public

ASP.NET MVC3 WebGrid - custom, server-side sorting

穿精又带淫゛_ 提交于 2019-12-29 08:53:09
问题 Is there a way to override default MVC3 WebGrid sorting behavior to call my controller (which will perform server side sorting and return the data) when sort is called? Thanks for any help! 回答1: You can pass the server side sorted data to the webgrid, along with the info on how many records there are. http://msdn.microsoft.com/en-us/magazine/hh288075.aspx has a helpful walkthrough. I'm doing database level sorting/filtering/paging to minimize the amount of data being passed around. I don't

MVC AutoComplete EditorFor while using Html.BeginCollectionItem

馋奶兔 提交于 2019-12-29 08:46:09
问题 I am trying to create an AutoComplete textbox, while using an EditorTemplate . The problem I am facing is that by using the Html.BeginCollectionItem() extension solution (https://www.nuget.org/packages/BeginCollectionItem/), the Id's of the EditorFor() and TextBoxFor() methods get set dynamically and this breaks my javascript. Next to that, I do not exactly know if this is even possible (and if so, how. Below you will find how far I have come). In the main view I have a loop to generate a

HTML is being rendered as literal string using RazorEngine. How can I prevent this?

北慕城南 提交于 2019-12-29 08:41:18
问题 I'm trying to generate a HTML document with RazorEngine (http://razorengine.codeplex.com/). Everything is mostly working, but the problem I have now is some of the HTML is being rendered correctly, and HTML that I have nested in that is being rendered as literal HTML, so rather than the browser displaying the tables & divs as expected, it's displaying e.g. "<table></table><div></div>" I kick off this process by calling the following: string completeHTML = RazorEngine.Razor.Parse(

Passing an array of ids from view pages to controller

谁说我不能喝 提交于 2019-12-29 08:29:30
问题 I discovered that the ids are not getting passed through from the razor page to the controller. So my int[] userIds is empty but I don't know why or how to fix it. Please help. Below is my code. Account Controller: public class AccountController : Controller { private readonly UserManager<ApplicationUser> _userManager; private readonly SignInManager<ApplicationUser> _signInManager; private readonly RoleManager<Role> _roleManager; public AccountController(UserManager<ApplicationUser>

ASP.NET MVC3: Interaction between Partial View and Main View

ⅰ亾dé卋堺 提交于 2019-12-29 08:22:34
问题 I have a partial view for contact. Currently the index view shows this partial view for contact details. There is a save button inside the partial view to save the edited data. There is a validation for age while saving the edited data. This much is working fine. Whenever user edit age and save it, I need to show the corresponding horoscope prediction on the main view. How do we achieve it? public class ContactEntity { public int ContactID { get; set; } public string ContactName { get; set; }

Render string containing razor-code in view

ⅰ亾dé卋堺 提交于 2019-12-29 08:01:35
问题 Thinking of CMS use cases here. Imagine a view like this: // /Home/Index.cshtml @model object @{ var str = "My <b>CMS</b> content with razor code: @Html.ActionLink(\"Click\", \"Home\")" } @Html.MyCustomRazorStringRenderer(Model) Expected output: My <b>CMS</b> content with razor code: <a href="/Home/Click">Click</a> What does MyCustomRazorStringRenderer look like? It must somehow do sth. like creating/using the ViewContext and render it (like here: Render a view as a string) but I can't quite