razor

Problem getting the AssemblyVersion into a web page using Razor /MVC3

梦想的初衷 提交于 2019-12-18 10:11:16
问题 I'm using the following code in a footer in my _Layout.cshtml file to put the AssemblyInfo version data into the footer of every page in my MVC3 site. However: @System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() Just prints in the footer: Revision 0.0.0.0 When I modified the view to display all of the assembly info for the "Executing Assembly" using the following @System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString() Which prints the following:

When should we use Html Helpers, Razor Helpers or Partial Views?

丶灬走出姿态 提交于 2019-12-18 10:03:12
问题 These three different features exist in the Razor view engine and can be used to achieve similar results. In the end all three of them just render pieces of HTML code, but the way to define and use them is fairly different. I know that: Html Helpers are created as extension methods for the HtmlHelper class. They frequently use the TagBuilder class to generate some HTML and always should return an IHtmlString . Razor Helpers ( @helper methods) can be defined locally (in the same razor file) or

how to set and get id of buttons created within a loop?

本小妞迷上赌 提交于 2019-12-18 09:53:44
问题 I have a loop that creates a button for each entry. However, I need to set a dynamic id for the button in order to use it and know the selected entry upon button click. My controller retrieves a list of entries from the database and using "ViewBag.List", I added the buttons. The list derrived from the database includes ID, Title and Description. This is the view/ Index.cshtml @model Exams.Models.subjects @{ ViewBag.Title = "Subjects" } <h2> Current Subjects </h2> <form method="post" action="

Access Javascript variable in Razor code

你离开我真会死。 提交于 2019-12-18 09:12:46
问题 I want to pass javascript variable in the C# method which is call from the Razor page. May I know how can I do that? (I refer this link but it did not work for me.) <script type="text/javascript"> function User(userID) { var redirectUrl = '@Url.Action("AddEditUser", "User")'; window.location.href = redirectUrl + '/' + @SomeMethod("stringvalue",**userID**); } Here userID is JS object and I want to pass in my server side method. I am getting errors like "Type or namespace definition, or end-of

Mixing razor and java script code for @Html.Partial()

廉价感情. 提交于 2019-12-18 08:56:52
问题 Can anyone provide me solution for how to dynamically add some code into the page in MVC. I was doing this way but in this code the page fails to identity index javascript variable , as it is not identifying the index javascript variable. $(document).on('click', '.add-option', function () { var index = $("div.ques-options").size(); if (index < 5) { $('.MainContainer').append('@Html.Partial("_Options", index)') } }); 回答1: it would be better to use jQuery load() or call by ajax action in the

Convert C# string to JavaScript String

女生的网名这么多〃 提交于 2019-12-18 08:47:14
问题 Does anybody know a way to convert a C# string to a JavaScript String in Asp.net. My code looks like this: <script> @{string thing = "Cats";} var thing = String(@thing); </script> </div> <body onload="eventAlert(thing)"></body> 回答1: You need to JavaScript Encode your string before you write it out, otherwise your string may contain characters that cause the JavaScript string constant to be terminated prematurely. You can do this with HttpUtility.JavaScriptStringEncode in the System.Web

Can Razor be used with visual studio 2008?

試著忘記壹切 提交于 2019-12-18 07:29:12
问题 Scott Gu didn't talk about this in his blog post. Will there be intellisense support for razor on vs 2008? MS is giving everyone a hard time by releasing major upgrades so frequently :D 回答1: No, not just Razor but MVC 3 will not be supported in VS 2008. The reason is that MVC 3 is being compiled on .NET 4.0 which is also not supported in VS 2008. 来源: https://stackoverflow.com/questions/3429336/can-razor-be-used-with-visual-studio-2008

Question about nested code block declarations in Razor

孤人 提交于 2019-12-18 07:28:33
问题 I've recently upgraded a project from MVC 1 to MVC 3 and now I'm trying out Razor. In one View, I have a foreach code block, but the nested if statement does not seem to want the @ in front of it. My original code was: @foreach(var r in Model.Results) { string css = r.Result.Count() > 0 ? "fail" : "pass"; <p class="@css"><strong>@r.Description</strong></p> @if(r.Result.Count() > 0) { <p>Count: @r.Result.Count()</p> <table> <thead> <tr> <th>ID</th><th>Title</th><th>Description</th> </tr> <

Post Form MVC with List of List

我只是一个虾纸丫 提交于 2019-12-18 06:49:56
问题 Most of the Tutorials, Questions I found online where about when the Model has one List of Items. But In my Case I have a List of Items which further have a List of Items. I have a ViewModel with List of ItemA , and ItemA has a list of ItemsB public class ViewModel { List<ItemA> Items { get; set; } public ViewModel() { Items = new List<ItemA>(); } } public class ItemA { public int ItemAId { get; set; } public List<ItemB> ItemBList { get; set; } public ItemA() { ItemBList = new List<ItemB>();

Visual Studio cannot resolve model, but Razor pages loads

旧时模样 提交于 2019-12-18 05:48:11
问题 I have an MVC 5 application, made from the empty template. I've added Microsoft.AspNet.Mvc via Nuget and my packages file looks like so: <packages> <package id="Microsoft.AspNet.Mvc" version="5.2.3" targetFramework="net46" /> <package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net46" /> <package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net46" /> <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net46" />