razor

ASP.Net MVC - Img Src Server Path

天大地大妈咪最大 提交于 2019-12-30 09:39:17
问题 Visual Studio 2012 - ASP.net - MVC 4 I am having troubles displaying an image from a server path which is stored in a database. I am using HttpPostedFileBase to retrieve the file the user has uploaded: using (var uow = _db.CreateUnitOfWork()) { if (imageUpload != null && imageUpload.ContentLength > 0) { var fileName = Path.GetRandomFileName() + Path.GetExtension(imageUpload.FileName); var path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads"), fileName); imageUpload

embedding javascript variable within razor syntax

亡梦爱人 提交于 2019-12-30 08:16:56
问题 I have a method that looks like this function endcall_click(leadid) { document.location = '@Url.Action("index","dispo",new{id=leadid})/'; } Of course it doesn't work because it treats "leadid" as a server side variable but I want to inject the javascript variable passed into the method. I tried wrapping lead id in but that didn't work. function endcall_click(leadid) { document.location = '@Url.Action("index","dispo",new{id="<text>leadid</text>"})/'; } Any ideas? 回答1: You can't inject

Inline markup blocks cannot be nested. Only one level of inline markup is allowed. MVC RAZOR

拈花ヽ惹草 提交于 2019-12-30 08:14:23
问题 I one one modal window with telerik grid inside. But i need to render images in my grid so as i understand i cant use @ twice. Here is blog post about this issue Link Can someone assist me please. My Code @{ Html.Telerik().Window() .Name("images") .Title("Select an Image") .Content(@<text> @(Html.Telerik().ComboBox() .Name("AjaxComboBox66") .AutoFill(true) .SelectedIndex(0) .BindTo(new SelectList(Model.PhotoFolders, "ID", "Name")) .Filterable(filtering => filtering.FilterMode

MVC 3 razor layout

浪子不回头ぞ 提交于 2019-12-30 08:02:01
问题 I have a MVC 3 project in which I use _Layout.cshtml as master page in all web pages. Now I want to remove this master page (layout) from one of the page (progress.cshtml). So I removed the removed the top portion of the page which was @{ ViewBag.Title = "Progress"; Layout = "~/Views/Shared/_Layout.cshtml"; } I thought this will work but when I browse progress page it still shows the content from layout file. How I can remove this binding? 回答1: Set the layout= null to remove the default

Calling JavaScript function in MVC 5 Razor view

回眸只為那壹抹淺笑 提交于 2019-12-30 06:30:06
问题 I have seen in another post that you can call a JavaScript function in your razor code like so: @:FunctionName() For me though this only outputs the actual words FunctionName() Here is my view: @model PriceCompare.Models.QuoteModel @{ ViewBag.Title = "Quote"; } <h2>Quote</h2> @if (@Model.clarify == true) { // do drop down loic @:ShowClarify(); } else { // fill quote @:ShowQuote(); } <div class="clarify"> You can see the clarify div </div> <div class="quote"> You can see the quote div </div>

MVC 3 Edit data in a IEnumerable Model View

£可爱£侵袭症+ 提交于 2019-12-30 06:18:10
问题 I'm trying to edit a list of items in a strongly-typed razor view. The templates don't give me the option to edit a list of objects in a single view so I merged the List view with the Edit view. I only need to edit one boolean field in a checkbox. The problem is that i cant get the data back to the controller. How do i do it? FormCollection ? Viewdata ? Thanks in advance. Here's the code: Models: public class Permissao { public int ID { get; set; } public TipoPermissao TipoP { get; set; }

@Html.DisplayText will not actually display text

折月煮酒 提交于 2019-12-30 05:45:07
问题 The following is the first section in the first row of a table on one of my ASP MVC3 Index pages. I've stepped through the code when that page loads, and can see that the evaluation of the conditions is done properly, however not of the "CE" or "PT" displays. I'm pretty new to ASP MVC, can someone help me with the syntax/explain what's going on? @foreach (var item in Model.Where(i => i.Status != "C")) { var Id = item.Id; <tr> <td> @if (!String.IsNullOrWhiteSpace(item.TableName)) { if (item

Limited Intelliesense in VS2013 on MVC3 project

喜欢而已 提交于 2019-12-30 05:43:14
问题 I recently installed vs 2013 professional and opened one of my side project applications in it . The project is an MVC3 application using the razor view engine. I noticed that when editing a view (cshtml ) I wasn't getting access to intellisense that I was used to in 2012. 2 Examples i noticed right away were @Url.Content() and @Viewbag. The code still compiles and runs, just no intellisense. After messing with it a bit i figured i should check the upgrade log and sure enough i found ...

How can I avoid looping in a View?

别等时光非礼了梦想. 提交于 2019-12-30 05:10:13
问题 When I build my views, I'd like to eliminate as much processing logic as possible. Ideally, I'd like to stick to just HTML and rendering values with Razor. So suppose I have a FooModel with a list of BarModel objects: public class FooModel { public List<BarModel> Bars { get; set; } public string FoosFirstValue { get; set; } public string FoosOtherValue { get; set; } } public class BarModel { public string SomeValue { get; set; } public string SomeOtherValue { get; set; } } And in my view, I

Output single quotes in Razor generated JavaScript String

余生颓废 提交于 2019-12-30 03:44:04
问题 I am assembling a few lines in JavaScript using Razor. I thought the easiest way would be to assemble the entire JavaScript block first, then output the entire thing. The problem is, the single quotes are being rendered as & #39;. Is it possible to change the last line to get this to write correctly: var friendArray = new Array(); @{ int i = 0; string jsString=""; foreach(var friend in friends) { jsString = jsString + "friendArray["; jsString = jsString + i.ToString(); jsString = jsString + "