razor

css class active after page reload

ε祈祈猫儿з 提交于 2020-01-02 09:03:57
问题 i'm having some trouble. I'm doing an asp.net mvc3 application and i downloaded some css menu, the thing is i want to keep the menu active after menu tab its clicked and only change when another one is clicked. here's the code of the menu on _Layout.cshtml <nav> <div class="cssmenu"> <ul> <li class='active'><span>@Html.ActionLink("Início", "Index", "Home")</span></li> <li><span>@Html.ActionLink("Tarefas Contabilidade", "SelectEmpresa", "Empresa")</span></li> <li><a href='#'><span>Clientes<

css class active after page reload

故事扮演 提交于 2020-01-02 09:02:15
问题 i'm having some trouble. I'm doing an asp.net mvc3 application and i downloaded some css menu, the thing is i want to keep the menu active after menu tab its clicked and only change when another one is clicked. here's the code of the menu on _Layout.cshtml <nav> <div class="cssmenu"> <ul> <li class='active'><span>@Html.ActionLink("Início", "Index", "Home")</span></li> <li><span>@Html.ActionLink("Tarefas Contabilidade", "SelectEmpresa", "Empresa")</span></li> <li><a href='#'><span>Clientes<

how do I test views using razor syntax in mvc3?

本秂侑毒 提交于 2020-01-02 08:44:14
问题 I am writing code to test an C# MVC3 application. I can test the controllers but how do I test the code in the views? This includes javascript and razor styled code. Are there any tools available which can mock out views or test views and javascript in C# in them? 回答1: The following is about testing the rendered output of the view. This textual output can for instance be loaded into a DOM for further analysis with XPath (using XmlReader for XHTML or HtmlAgilityPack for SGML-style HTML). With

Shopping Cart logic (?) trouble with KnockoutJS

好久不见. 提交于 2020-01-02 07:29:20
问题 The Goal Make a dynamic list of products. The Scenario I have a shopping application with products. When I click on the add button of a product, I want to display in the sidebar, the product what I have added. Summarized Problem (You just need to read this) I have the following code in my ProductsSummary/Index.cshtml (using Razor Engine): <ul class="summary"> @if (Session["ProductsSummary"] == null) { <li class="is-empty"> <p>Your summary is empty.</p> </li> <li data-bind="attr: { 'data

Why can't I get LINQ to work in my .cshtml files?

懵懂的女人 提交于 2020-01-02 07:13:35
问题 I'm working in VS 2017, targeting .NET Framework 4.6.2, and I've been running into this in a few different projects. I believe the projects were initially created in VS 2012, for what it's worth. I'm able to use Linq extensions and query syntax with no problems whatsoever in any of the .cs files, but if I try a line like this in a .cshtml razor file: @{ var activeCategories = Model.Categories.Where(x => x.Articles.Count > 0).Count(); } <p>Active Categories: @activeCategories</p> I get an

JavaScript variable carry an ID that I need to use in a Html.ActionLink

半世苍凉 提交于 2020-01-02 06:54:30
问题 I have a JavaScript variable in my jQuery code that contains an ID that I need to use in my Html.ActionLink but it's not working: @(Html.ActionLink("Genomför", "AnswerForm", "AnswerNKI", new {id = goalcard.Id},null)) I get: 'cannot resolve symbol "goalcard"', and the reason is that goalcard is a JavaScript variable. This is what it looks like: $.post('@Url.Action("Search", "SearchNKI")', data, function (result) { $("#GoalcardSearchResult tbody").empty(); result.forEach(function(goalcard) { $(

Adding a CSS class to razor @Html.DisplayFor

老子叫甜甜 提交于 2020-01-02 06:44:08
问题 I want to set a new class for this part of my code, but it doesn't work correctly @Html.DisplayFor(model => model.melk.Code, new { @class = "myClass" } ) Can anyone tell me where am I wrong? 回答1: The DisplayExtensions.DisplayFor overload that you are using will find the DisplayTemplate based on the type of the model.melk.Code and the last parameter (anonymous object new { @class = "myClass" } will be passed to the template's ViewData. You have to use that ViewData in the corresponding

Razor.Parse alternative

▼魔方 西西 提交于 2020-01-02 06:39:11
问题 We have a default value for a textbox that is coming from a database and it is @UserSession.NumberOfPeople This is currently parsed by using string value = Razor.Parse(Model.DefaultValue) Which returns me the string value from that variable However as Razor.Parse is now obsolete, I was looking into an alternative way using Engine.Razor.Compile but I can't seem to find an overload that isn't requiring a template Is there a way of just parsing the the value as it is string value = Razor.Parse("

MVC-4 FileUpload success message

删除回忆录丶 提交于 2020-01-02 05:30:12
问题 I am having few problems with displaying a success message after a file has been uploaded. I first tried with using the ViewBag.Message , and it works good and display the Success message after the file has been uploaded, which is what I want. But then I cant find a way on how to , after a few seconds change that message back to: "Choose a file to upload !" , so that the user understand he can now upload a new file. I tried to implement a javascript feature to handle the success message

“Bogus” Web project requires missing web component message for razor

久未见 提交于 2020-01-02 05:23:14
问题 Using Visual Studio 2010, MVC 3 (release version) I'm getting this error when opening a specific project which was a traditional web forms project to which I've added MVC: "The Web project '' requires missing web components to run with Visual Studio. Would you like to download and install the using the Web Platform Installer now? ASP.NET Web pages with Razor syntax." I have MVC installed and fully running. Other pure MVC and another mixed Web Forms/MVC project open without any issue. Clicking