razor

Simple html vs extension methods in Razor (preference)

妖精的绣舞 提交于 2020-01-03 09:45:18
问题 For Simple tags in MVC Razor do you prefer to use simple HTML or use extension methods eg <label for="male">Male</label> Or @Html.Label("male", "Male") I feel it is sometime more easier to use the simple HTML. Extension methods make sense when you want to do some custom code. 回答1: Depends. If the male element you are associating this label to is rendered with a html helper like: @Html.TextBoxFor(x => x.Male) then I would use a Html.LabelFor and keep the lambdas and strong typing. Also I would

ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

橙三吉。 提交于 2020-01-03 08:29:04
问题 The Razor view engine in ASP.NET MVC supports @helper to define little helper methods. It seems you can do much the same by adding extension methods to HtmlHelper. In what situations is it best to use each? 回答1: Subjective question, so here's my subjective and biased answer: When the helper code involves amounts of C# code use a custom HtmlHelper and when it's primary markup you could use @helper . But assuming that when you have markup you could use a partial like @Html.Partial("_foo",

ASP.NET MVC: Razor @helper vs extension methods to HtmlHelper - which is preferred?

安稳与你 提交于 2020-01-03 08:28:05
问题 The Razor view engine in ASP.NET MVC supports @helper to define little helper methods. It seems you can do much the same by adding extension methods to HtmlHelper. In what situations is it best to use each? 回答1: Subjective question, so here's my subjective and biased answer: When the helper code involves amounts of C# code use a custom HtmlHelper and when it's primary markup you could use @helper . But assuming that when you have markup you could use a partial like @Html.Partial("_foo",

ASP.NET MVC 3 jquery : French accent characters are showing as #233 characters on screen

时光总嘲笑我的痴心妄想 提交于 2020-01-03 08:09:29
问题 I have ASP.NET MVC 3 application having resource files in english and french . A text ' Sélectionner la pharmacie ' is stored in a french resource file. When the value is read from resource files with razor syntax, it shows ' S#233;lectionner la pharmacie ' instead of ' Sélectionner la pharmacie '. e.g. @MyResources.Strings_Resources.lbl_SelectPharmacy Is there a way I can make it show the french accent characters ? 回答1: I suspect that your text is already encoded and razor is trying to

Razor pages in MVC are giving a compile error with System.Web.Helpers not being found

主宰稳场 提交于 2020-01-03 06:58:05
问题 My razor view is failing to compile with the following error: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0234: The type or namespace name 'Helpers' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) I have System.Web.Helpers added as a reference to my project, so I am not sure what

How to use a 'checkbox' to update present address to same as permanent address

浪尽此生 提交于 2020-01-03 06:36:18
问题 Often when creating a form on a web page, I need our customers to fill out a field such as a permanent address, as well as a present address( when checked check box then present address fill automatically). Instead of having our customers fill out the form twice,I can use JavaScript to copy the form's data from one field to another. @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div> <div class="well"> <b>Parmanent Address </b> </div> <div class="row"> <div class="col-md-6"> <div class

How to Move Zero Qty Products to the end of List when i have a PagedList<Products>?

ε祈祈猫儿з 提交于 2020-01-03 05:35:06
问题 I have a method in my controller which returns a PagedList to my category-page View that contains Products (based current Page-Number and Page-Size which user has selected) from SQL Server stored-procedure like blow : var products = _dbContext.EntityFromSql<Product>("ProductLoad", pCategoryIds, pManufacturerId, pOrderBy, pageIndex, pageSize).ToList(); // returning products based selected Ordering by. var totalRecords = pTotalRecords.Value != DBNull.Value ? Convert.ToInt32(pTotalRecords.Value)

Use htmlhelper to get action in BeginForm() Method of ASP.NET MVC 3

最后都变了- 提交于 2020-01-03 05:08:13
问题 In ASP.NET MVC 3 we always use using(@html.BeginForm(){ } helper (assume using without any parameters) to use forms with postback. The returned html, includes an open form tag with some attributes and action that represent the postback url. So when I overwrite my custom BeginForm helper I need this Url. This action attribute is not just action name or combination of {area}/{controller}/{action} . I think this is a same url we use to see the current page, because when we submit page we backed

Passing data from my razor view to my js file

我怕爱的太早我们不能终老 提交于 2020-01-03 05:00:13
问题 I'm searching for the best way to pass data from my razor view to my js file . For example, lets say we have a jquery dialog configured in the js file. For buttons text on this dialog, I would like to localize it (through resource files FR/NL/UK). The translations are available with @UserResource.ButtonDelete + @UserResource.ButtonCancel Below are the different solutions I see: Using the nice RazorJS nuget package to allows razor code inside my javascript file. It works pretty well. But the

How to call ASP MVC CSHTML View directly with “.cshtml” extension from browser

☆樱花仙子☆ 提交于 2020-01-03 04:56:11
问题 I want to call my asp mvc CSHTML View directly from browser with ".cshtml" extension like: www.mysite.com\receive.cshtml?... instead www.mysite.com\receive?... but i got 404 any idea ? 回答1: 1. By default IIS Request Filtering is configured not to serve requests to .cshtml files. 2. Razor views are not meant to be accessed directly by the client. yet, take a look at https://github.com/ServiceStack/RazorRockstars 来源: https://stackoverflow.com/questions/17803638/how-to-call-asp-mvc-cshtml-view