razor

Generating dynamic XML in Razor

孤街浪徒 提交于 2019-12-20 01:09:07
问题 I am using Razor outside of ASP.NET to generate XML documents from a template. I have the following code: <event> <timeouts trigger='@Model.TriggerTimeout' /> <parameters> @foreach (var parameter in Model.Parameters) { <@parameter.Key>@parameter.Value</@parameter.Key> } </parameters> </event> where Model.Parameters is just a name/value collection. My expected output should be: <event> <timeouts trigger='100' /> <parameters> <name1>value1</name1> <name2>value2</name2> <name3>value3</name3> <

ASP.NET Binding linq query results to HTML.DropDownList() using MVC

无人久伴 提交于 2019-12-19 21:19:49
问题 I am trying to build a drop down list with a single database call. My table consists of an Id column and a CompanyName column. I need to display the CompanyName to the user and when one is selected set the Id for the page to Id. I have put a simple model together to store the information: using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Web; namespace Portal.Models { public class CompanyListId { public int Id { get; set; } public string

Tag Helpers disabled in VS 2015

妖精的绣舞 提交于 2019-12-19 19:56:16
问题 I am having trouble getting Tag Helpers enabled in my project. Here is a summary of the project setup: VS 2015 RC Community Edition. Project.json reference: Microsoft.AspNet.Mvc": "6.0.0-beta4 _GlobalImport.chtml has @addTagHelper"*,Microsoft.AspNet.Mvc.TagHelpers" No build errors or warnings. Must missing something, but I don't know what. UPDATE: Seems I am part of the way there. I added @addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers" to the _ViewStart.chtml. Razor is now processing

Razor engine cant find view

蓝咒 提交于 2019-12-19 18:28:07
问题 Im trying to render a html from a view without using a web request. I need the HTML as a string, internally, i do not wish to serve it. The viewEngine.FindView() returns a viewEnineResult that shows no view was found. It shows to search locations where it looked they look like this: /Views//PDFOperationsReportView.cshtml /Views/Shared/PDFOperationsReportView.cshtml (Observe the double forward slash in the first line) File structure (I placed it into a HTML snippet cause i couldnt manage to

Is there a risk in using @Html.Raw?

≡放荡痞女 提交于 2019-12-19 17:47:08
问题 Is there a risk in using @Html.Raw ? It seems to me there shouldn't be. If there is a risk then wouldn't that risk already exist regardless of using @Html.Raw in that modern browsers such as Chrome will allow an edit injection of <script>malicious()</script> or even to change a form's post action to something else. 回答1: @Html.Raw will allow executing any script that is on the value to display. If you want to prevent that you need to use @Html.AttributeEncode 回答2: Correct, the risk is in how

Razor code between double quotes

前提是你 提交于 2019-12-19 17:15:32
问题 In a Razor View Engine template, I want to do the following: I want to put some code between the double quotes of an html attribute . The trouble is that the piece of code I want to insert contains some double quotes itself. <a href="Url.Action("Item", new { id = Model.Item.Id, page = page });">@page</a> You can easily see how things turn horribly wrong :-) I know i can calculate the link in a variable and then use it, but I'd rather not: @{ var action = Url.Action("Question", new { id =

Razor code between double quotes

青春壹個敷衍的年華 提交于 2019-12-19 17:15:12
问题 In a Razor View Engine template, I want to do the following: I want to put some code between the double quotes of an html attribute . The trouble is that the piece of code I want to insert contains some double quotes itself. <a href="Url.Action("Item", new { id = Model.Item.Id, page = page });">@page</a> You can easily see how things turn horribly wrong :-) I know i can calculate the link in a variable and then use it, but I'd rather not: @{ var action = Url.Action("Question", new { id =

How to access My.Resources from a razor view

我怕爱的太早我们不能终老 提交于 2019-12-19 14:43:19
问题 I have a razor .vbhtml view and would like to use string resources normally accessible via My.Resources. Seems like I can only get to My.Computer, My.Log and couple other namespaces from the view, but not My.Resources. I've tried changing access modifier to public and adding @Imports, neither worked. Thanks 回答1: Add a Messages.resx file to your project. In the properties of this file in the solution explorer set Custom Tool = PublicResXFileCodeGenerator . Now inside the view you can directly

ASP.NET MVC3 Razor - Auto-complete Tutorial?

我怕爱的太早我们不能终老 提交于 2019-12-19 12:51:06
问题 How do you implement auto-complete with ASP.NET, MVC3, and Razor? 回答1: You could use jQuery UI Autocomplete control along with an mvc action that returns a JsonResult with the right data 回答2: This isn't using Razor but translating it from webforms to razor is pretty trivial: http://tpeczek.com/2010/05/jquery-autocomplete-in-aspnet-mvc.html 来源: https://stackoverflow.com/questions/5033060/asp-net-mvc3-razor-auto-complete-tutorial

google map with multiple markers is not appearing

若如初见. 提交于 2019-12-19 11:56:45
问题 I want to display multiple markers on google map.I am using for each loop to iterate over the model list that contains latitude and longitude.But function is called and it does not show a map. code: <div id="map_canvas" style="width: 80%; height: 80%"> </div> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"> </script> <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js? sensor=false"></script> <script type="text/javascript"> $(document)