razor

Razor HtmlHelpers with sub-sections?

こ雲淡風輕ζ 提交于 2019-12-24 11:21:23
问题 Is there a way to build the custom Html Helpers and put them into sub-sections? I.e: @Html.Buttons.Gray @Html.Buttons.Blue @Html.Tables.2Columns @Html.Tables.3Columns Thanks. 回答1: Helpers are simply extension methods. So you could create helpers that return object that allow you to chain method calls, e.g. @Html.Button("Text").Grey() . public ButtonHelper { public string Text {get; set;} public MvcHtmlString Grey() { return MvcHtmlString.Create("<button class='grey'>"+ Text +"</button>"); } }

Asp.net mvc wizard - Need some guidance

与世无争的帅哥 提交于 2019-12-24 10:58:48
问题 I need some help creating a wizard in asp.net mvc. This wizard will contain about 7 or 8 steps. Here's how i've modeled the controller and i was hoping to get some feedback on whether this is the correct approach or to see if there are any better ways that someone here can recommend. I've created a separate view model class for each of the steps. I have a Wizard class which contains each of these seperate models + Properties like CurrentStep etc. I've created a separate view for each of the

IE only - A potentially dangerous Request.Form value was detected from the client (MVC-Razor)

不想你离开。 提交于 2019-12-24 10:56:54
问题 I'm doing a simple replace statement on a file with input from 2 textboxes and 2 drop down lists. Platform is MVC 3, on a Razor page. Problem is that the error is only thrown on IE, and only when published out on the server. Running the site from localhost on IE throws no errors. I'm really curious as to why this is just an IE problem (It works fine in Chrome and Firefox) Here's the code from the page: <div class="form"> @using (Html.BeginForm("AddZipCode", "DatabaseHelper")) { <!-- <div

How to use relative virtual path in custom razor view engine

限于喜欢 提交于 2019-12-24 10:55:50
问题 i am using a custom razor view engine with overridden MasterLocationFormats. I want to give relative virtual path locations for searching views and master pages. How can that be done? public class ExampleRazorViewEngine : RazorViewEngine { /// <summary> /// Initializes a new instance of the <see cref="ExampleRazorViewEngine"/> class. /// </summary> public ExampleRazorViewEngine() { ViewLocationFormats = new string[] { "../../../Views/{1}/{0}.cshtml", }; MasterLocationFormats = new string[] {

Angular ng If not working with razor syntax

微笑、不失礼 提交于 2019-12-24 10:51:02
问题 I am using Angular Js with Razor. @{ var pageMode = (string) ViewBag.PageMode; } <div ng-if="@pageMode == 'answer'"> <h2>Greetings</h2> </div> Value is in ViewBag.PageMode is "answer", still the ng if does not render. i.e "Greetings" message does not work. What am I doing wrong here... ? 回答1: you cant use var pageMode variable inside directives like ng-if . you need to use $scope variable. so, simplest thing u can do is, @{ var pageMode = (string) ViewBag.PageMode; } <input type="hidden" ng

clickable rows in web grid, with razor/javascript

我怕爱的太早我们不能终老 提交于 2019-12-24 10:48:41
问题 Using the webgrid helper I've used some JavaScript to have the entire row clickable, and that works fine, however the href link in the JavaScript i need to incorporate razor. javascript code here: <script type="text/javascript"> $(function(){ $('tbody tr').live('hover', function(){ $(this).toggleClass('clickable'); }).live('click', function(){ location.href = '/Messages/Reply/' + $(this).find('td:first').text(); }); }); </script> But this code is taking the value in the first cell and using

Populating ListBoxfor with ViewModel and passing back its contents

亡梦爱人 提交于 2019-12-24 10:46:48
问题 I am struggling to figure out how to pass back my model (unmodified) back to my controller. I have tried binding my ViewModel to many different HTML.Helpers and what not. I can get my data to bind and display, but I cannot get the ViewModel to post back to my controller. I have the following ViewModels: public class MediaProviderViewModel : ViewModelBase { public int MediaProviderId { get; set; } public string MediaProviderName { get; set; } public static MediaProviderViewModel FromEntity

How to get the Tempdata in javascript?

筅森魡賤 提交于 2019-12-24 10:46:46
问题 I have this method in my Controller that saves the value in a Tempdata, as shown below. public Boolean SaveSession(string id) { TempData["CurrentTab"] = id; return true; } Now in my javascript, I want to get the value in that TempData. But when I alerted the value I got this value. "[object HTMLSpanElement]" @{ if (TempData["CurrentTab"] != null){ @:alert("" + @TempData["CurrentTab"].ToString()) } } How can I get the string value of that Tempdata? Thanks 回答1: The problem is that you're

Cannot open any CSHTML file in a certain project [closed]

六眼飞鱼酱① 提交于 2019-12-24 10:39:27
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 5 years ago . When I open a CSHTML file in one specific ASP.NET MVC project, visual studio 2013 crashes. I can open other files in this project and I can open CSHTML files in other projects. I and a coworker work with this project on other computers without trouble. I've deleted the entire project from my

virtual view inheriting from System.Web.Mvc.ViewStartPage

可紊 提交于 2019-12-24 10:21:18
问题 I had an issue with when trying to retrieve virtual views from a file by means of VirtualPathProvider, which is described in this stackoverflow thread. Now my question is why does a virtual view inherits from System.Web.Mvc.ViewStartPage, and how to make it to inherit from WebViewPage so that I can use ViewResult View(string viewName); instead of PartialViewResult PartialView(string viewName); like in described workaround? 来源: https://stackoverflow.com/questions/13363273/virtual-view