razor

Maintain whitespace when displaying text from database

拈花ヽ惹草 提交于 2019-12-21 20:36:30
问题 I'm putting up a table that displays values from a table. One of the fields comes from a textarea input. If I use this method then whitespace is maintained: @Html.TextAreaFor(model => model.goalDescr, new { cols="90", rows="3", @readonly = "true"}) --example: hey there --end example However, I don't like that view so much as it still looks like a form field. I tried to use displayfor but the white space is removed and all text is one one line. @Html.DisplayFor(model => model.goalDescr) -

Problem using Razor after migrating MVC 2.0 to MVC 3.0 RC

↘锁芯ラ 提交于 2019-12-21 19:56:55
问题 I migrated a MVC 2.0 site to MVC 3.0, using that : Migrating MVC 2.0 -> 3.0 Using ASPX as View Engine works great now... But I tried to create a Razor view and got that error: The view 'TestView' or its master was not found. The following locations were searched: ~/TestView.aspx ~/TestView.ascx ~/Views/Color/TestView.aspx ~/Views/Color/TestView.ascx ~/Views/Shared/TestView.aspx ~/Views/Shared/TestView.ascx How can I enable razor on that? I´m using Visual Studio 2010... Creating a brand new

How deny access direct URL to my partial views?

北慕城南 提交于 2019-12-21 19:47:23
问题 I have some partial views in my controller. The problem is that users can visualize my partial views if they put in url: (www.mydomain.com/mycontroller/mypartialview). How can I deny direct access... and allow work with partial views only from base view? Thank's! 回答1: add [ChildActionOnly] .. like this : [ChildActionOnly] public PartialViewResult List(Model model) {... return PartialView(model); } 回答2: As Andras says, this would only happen if you have a controller action to return them. I

return view after ajax call

不问归期 提交于 2019-12-21 17:48:08
问题 after an async call with jquery how can I return a particolar view? this my caller view: <script type="text/javascript"> function Run() { $.ajax({ type: "POST", cache: false, url: "/Home/Run", data: $("#form_run").serializeArray(), dataType: "json" }); } </script> <form action="javascript:return true;" method="post" id="form_run"> <input type="text" id="nome" name="nome" /> <input type="text" id="cognome" name="cognome" /> <input type="submit" name="submit" value="Run" onclick="Run();" /> <

Best practice for using interface type as model in View and use real type attributes and validations

北战南征 提交于 2019-12-21 17:43:24
问题 I have such interface: public interface IFoo { decimal Amount { get; set; } } And I have some view models implement it: public class Foo1 : IFoo { [Display(Name = "Foo1 Amount")] [Range(6, 11)] public decimal Amount { get; set; } } public class Foo2 : IFoo { [Display(Name = "Foo2 Amount")] [Range(1, 5)] public decimal Amount { get; set; } } I don't want to create a new view for each of Foo1 and Foo2 . So, I have created a view which has IFoo type model. @model IFoo <div> @Html.LabelFor(x => x

MVC3 Razor - Is there a way to change the Layout depending on browser request?

≡放荡痞女 提交于 2019-12-21 17:38:51
问题 I followed this tutorial with success: http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx All view are rendered with success when I access the page with mobile device. But, they are rendered with wrong layout (AKA masterpage). I have the following structure: /Views/Shared/Mobile/_Layout.cshtml /Views/Shared/_Layout.cshtml The problem is, I have to put the following statement in EVERY view: Layout = "~/Views/Shared/Mobile/_Layout.cshtml"; Is

ASP.NET MVC: Razor - How to keep nicely indented code without sending a load of white space to the browser

时光怂恿深爱的人放手 提交于 2019-12-21 17:20:04
问题 I am using razor to render out javascript objects, as shown in the following code snippet @{ bool isFirst = true; foreach (var qa in Model.Form.FormItems) { if (isFirst) { isFirst = false; } else { @:, } @:new QuestionAndAnswer( @:@(qa.QuestionAnswerId), @:@(qa.OrderNumber), @:@(qa.ParentOrderNumber), @:@(qa.IsHeader.ToJsonValue()), @:@(qa.IsMandatory.ToJsonValue()), @:@(qa.IsAlertable.ToJsonValue()), @:@(qa.IsAlarmable.ToJsonValue()), @:@(qa.IsKeyItem.ToJsonValue()), @:@(qa.IsHiddenQuestion

.NET MVC 3 Programmatically set layout

寵の児 提交于 2019-12-21 16:59:35
问题 In a .NET Razor Web Application i'm trying to programmatically set the Layout . I can not use _ViewStart.cshtml and don't wont to set the @{ Layout = "..." } on every page. This is what I have come up with: A base WebViewPage class: public abstract class SitePage<T> : System.Web.Mvc.WebViewPage<T> { private object _layout; public new dynamic Layout { get { return _layout; } } public override void InitHelpers() { base.InitHelpers(); _layout = "~/Themes/" + Settings.Theme + "/Views/_Layout

How to add individual css file in particular view in mvc4?

。_饼干妹妹 提交于 2019-12-21 16:18:13
问题 Actually I've a master page and I'm adding this master page into another view (Index.cshtml), now I want to add another individual css file into Index.cshtml view. 回答1: In the head section of your master page (e.g. _Layout.cshtml) add a RenderSection call. Your header section could look like this: <head> <meta charset="utf-8" /> <meta name="description" content="The content description" /> <link rel="shortcut icon" href="@Url.Content("~/Content/images/favicon.ico")" /> <title>@ViewBag.Title<

Embedding SVG in ASP.net page

时光毁灭记忆、已成空白 提交于 2019-12-21 12:49:55
问题 I would like to embed svg directly into my ASP.net-MVC view so that the output looks something like this: <html> <body> <svg> ... </svg> </body> </html> With PHP I would do this like so: <? include('image.svg'); ?> I tried @Html.Partial('image.svg') but got an error. Is there a way to fix this or another method I can try? 回答1: Embed your SVG into a cshtml view file instead of a .svg file, then you should be able to use @Html.Partial to render it. Your partial would then look like @Html