razor

Access a Viewbag like an Array?

为君一笑 提交于 2019-12-19 08:52:13
问题 Imagine a view bag called ViewBag.Modes this contains the following: Simple Advanced Manual Complete How can I access the viewbag by index like you would in an array? e.g Simple is at index 0 then it would look like this ViewBag.Modes[0] I tried the above but it doesn't work so...How can I replicate this with viewbag or is there a workaround I can use? 回答1: This does the trick for me: Controller: public ActionResult Index() { var stringArray = new string[3] { "Manual", "Semi", "Auto"};

Certain Razor views not publishing

喜你入骨 提交于 2019-12-19 08:11:56
问题 Using VS 2017 with MVC 5 Razor views. When I publish my application, a handful of specific views do not get copied over. I'd discovered several SE questions on this same issue from back in the 2010-2011 timeframe. At the time, the issue was that Build Action in the file's properties was not set to Content due to a bug in some early RC which has since been resolved. Well, all of mine already do day Content for Build Action. Any reason why only a small number of views are not making it in the

Async method call in Razor view

限于喜欢 提交于 2019-12-19 08:04:04
问题 I have @Html.Translate() extension method, which returns translated string. Translations are stored in database, so I want to make async call to database from helper method. Can I make async method calls from razor view? Is here some workaround to call async methods in razor view? 回答1: Async method calls from razor view are supported (or will be supported) only in ASP.NET vNext (MVC 6). If you are using MVC 5 version and eralier, the simplest solution to your problem would be adding a

Async method call in Razor view

谁说我不能喝 提交于 2019-12-19 08:02:25
问题 I have @Html.Translate() extension method, which returns translated string. Translations are stored in database, so I want to make async call to database from helper method. Can I make async method calls from razor view? Is here some workaround to call async methods in razor view? 回答1: Async method calls from razor view are supported (or will be supported) only in ASP.NET vNext (MVC 6). If you are using MVC 5 version and eralier, the simplest solution to your problem would be adding a

razor views in asp.net web project

半城伤御伤魂 提交于 2019-12-19 07:32:09
问题 I am currently researching view engines and Razor Views have become very interesting to me. I am in process of developing an asp.net 4.0 web forms application. Razor views examples from what I could find are predominantly with MVC applications. Is it possible to integrate Razor views in to a web forms application? Is it beneficial to do so? The main reason I look to do this is to create a new layer for my applications architecture and possibly a new area that can be tested. 回答1: Of course you

OpenFileDialog in cshtml

梦想的初衷 提交于 2019-12-19 07:22:47
问题 may I know hot can I write something like this c# Opendialog in Razor? I'm trying to make an openfiledialog that would offer user to upload photo into SqlServerCe database: OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { string path = openFileDialog1.FileName;

Heavy use of ViewBag

限于喜欢 提交于 2019-12-19 06:57:34
问题 I make heavy use of the ViewBag in my MVC application, is this considered bad practice? I'm unsure as to whether to spend time creating ViewModels (however I thought that was more suited to MVVM rather than MVC) or continue using the ViewBag heavily. What are the arguments for and against this? Example controller method would return it's model (generally a simple domain entity) as well as the following calls to the ViewBag: ViewBag.TotalItems = data.Count(); ViewBag.FilteredItems =

How to tell Ajax.ActionLink OnSuccess callback which element initiated the ajax

若如初见. 提交于 2019-12-19 06:54:16
问题 I want my razor view to look something like this @Ajax.ActionLink("A", "Buy", new AjaxOptions() { HttpMethod = "Post", OnSuccess = "updateLetter" }, new { id = "letter-A" }) @Ajax.ActionLink("B", "Buy", new AjaxOptions() { HttpMethod = "Post", OnSuccess = "updateLetter" }, new { id = "letter-B" }) @Ajax.ActionLink("C", "Buy", new AjaxOptions() { HttpMethod = "Post", OnSuccess = "updateLetter" }, new { id = "letter-C" }) and my javascript to look something like this function updateLetter

How dangerous is it to let users specify RazorEngine templates?

我与影子孤独终老i 提交于 2019-12-19 06:52:40
问题 I have mail-merge like functionality, which takes a template, some business object, and produces html which is then made into PDF. I'm using RazorEngine to do the template+model to html bit. If I let the users specify the templates, what risks am I taking? Is it possible to mitigate any risks? For example, could the users execute arbitrary code? (delete files, alter database, etc.?) Is there some way I can detect this sort of thing? (I know that would be impossible generally, but the bits of

What is the difference between “@Scripts.Render” and “<script>”? [duplicate]

一曲冷凌霜 提交于 2019-12-19 06:35:09
问题 This question already has answers here : Why use @Scripts.Render(“~/bundles/jquery”) (2 answers) Closed 6 years ago . I want to know about the difference between @Scripts.Render("~/something.js") and <script type="text/javascript" src="/something.js"></script> . Yes, I've already searched about this subject, but with no success. I think if @Scripts.Render exists isn't by chance. More details What I'm meaning is: when I should use one or other and why. 回答1: Scripts.Render is used for bundling,