razor

How to register assembly in Razor view engine

*爱你&永不变心* 提交于 2020-01-02 04:07:13
问题 How can i insert this in razor view page <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %> <asp:ScriptManager runat="server" ID="MainScriptManager" /> 回答1: You can put it in the Web.Config that exists in your Views folder . It took me a while to figure this one out hope this helps. <system.web> <controls> <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc"

Using angular attributes with TextBoxFor in ASP.NET MVC

你。 提交于 2020-01-02 03:50:27
问题 I am using ASP.NET MVC with AngularJs. I am new to AngularJs, I am trying to create a form that uses angularjs. So to start with I have a login form which asks for username and password. The username using Html.TextBoxFor as shown below @Html.TextBoxFor(m => m.UserName, new { ng-model="user.name" }) But the ide shows the ng-model as an error in red. and gives an error when run with this change. Error message account/login - c:\SVN HOME\ABC-SelfServe\src\ABC\Web\Views\Account\Login.cshtml(23):

Render dynamic HTML with embedded Razor variables using MVC

ⅰ亾dé卋堺 提交于 2020-01-02 03:46:27
问题 I have some encoded Html which have any number of 1000s of different Razor variables embedded within it that I have stored and need to retrieve from the database . I want to be able to render this in a MVC/razor view. Just one simple example of the html saved on the database (it can be more complex): "<span>Your page is @Config.PageColour and you have page size of @Config.PageSize</span>" MessageController.cs public ActionResult ShowMessage() { var htmlToDisplay = _messageDAL.getHtmlMessage()

Accessing Session object inside an Asp Core 2 View

北战南征 提交于 2020-01-02 03:45:07
问题 I want to show Session in view. Is that possible? I try with this in my view <div class="content-header col-xs-12"> <h1>Welcome, @HttpContext.Session.GetString("userLoggedName")</h1> </div> But i get an error Severity Code Description Project File Line Suppression State Error CS0120 An object reference is required for the non-static field, method, or property 'HttpContext.Session' Any help, i will appreciate it. Thanks 回答1: You can inject IHttpContextAccessor implementation to your view and

Razor in class library, missing intellisense

给你一囗甜甜゛ 提交于 2020-01-02 03:42:08
问题 I'm trying to include razor (cshtml) files in a class library, to be included in a separate MVC4 project. I've gotten everything working, except intellisense seems to be missing for certain types, specifically System.Web.Helpers.Json , although there could be others I haven't discovered yet. My problem might be related to Razor views: Intellisense not working with C# 3 for class libraries but it's not exactly the same. Here is a sample from my razor view: @model dynamic @{ // ... some code ..

difference between: [ScaffoldColumn (false)] and [Display (AutoGenerateField = false)]

笑着哭i 提交于 2020-01-02 03:35:27
问题 To render HTML in my edit view, I use the helper @Html.EditorForModel() . My model: [Required(ErrorMessage = "Campo obrigatório")] [Display(Name = "Nome completo")] public string Name { get; set; } [Required(ErrorMessage = "Campo é obrigatório")] [StringLength(100, ErrorMessage = "A {0} deve ter pelo menos {2} characteres.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Senha")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirmar

Convert MVC 2 ASPX into MVC 4 Razor view engine

蹲街弑〆低调 提交于 2020-01-02 02:22:25
问题 I am currently working on MVC 2 with visual studio 2010 and view engine as ASPX kind of project. So I have decided to move with Visual studio 2012 with MVC 4 and view engine as Razor . So could I achieve above task.If so How ? I would like to hear your experience for similar kind of situation. Note : My project is a large one. 回答1: Create a new MVC4 project in Visual Studio 2012 and add source files from your old solution to your new solution one at a time. Moving from MVC3 to MVC4 is easier

Inline If in Razor View

有些话、适合烂在心里 提交于 2020-01-02 01:29:10
问题 In my controller, I have and inline If statement: ViewBag.NameSortParam = If(String.IsNullOrEmpty(sortOrder), "Name desc", "") In my view, I can't seem to use inline if: @Code If(True, true, true) End code It says, "If must end with matching End If." Why can't I use an inline if here? Thanks. 回答1: Try @Code @(If(True, true, true)) End Code 回答2: You could use something like this: @(true? "yes": "no") 回答3: You can do an inline if in vb.net like this: @(If(testExpression, TruePart, FalsePart))

Get a text item from an c# SelectList

ⅰ亾dé卋堺 提交于 2020-01-02 01:17:21
问题 Using Visual Studio Express 2012 for Web and Razor, I create a select list: List<SelectListItem> list = new List<SelectListItem>(); list.Add(new SelectListItem { Text = "Yes", Value = "1" }); list.Add(new SelectListItem { Text = "No", Value = "2" }); SelectList selectList = new SelectList(list, "Value", "Text", null); Later, I want to get the text associated with a specific element in selectList. As a newbie, I'd think I could do this: selectList.Items[1].Text But that results in the message,

Syntax error in Razor view when passing model properties as parameters to javascript function

房东的猫 提交于 2020-01-02 00:56:11
问题 I get a Syntax error on each comma ( , ) and on the last bracket ( ) ) in the following code: <script type="text/javascript"> Filters.priceRangeInit(@Model.Min, @Model.Max, @Model.From, @Model.To); </script> The javascript function is in another file and looks like this: Filters = { priceRangeInit: function (min, max, from, to) { $('#price-range-slider').slider({ min: min, max: max, step: 50, values: [from, to], slide: function (event, ui) { $('#left-price-range-amount').val(ui.values[0]); $(