razor

What is the difference between Razor and ASPX?

痴心易碎 提交于 2019-12-17 18:45:45
问题 Is there any difference between Razor and ASPX in a MVC project? Is it just about syntax? That's what I think after reading this... Am I wrong? 回答1: I guess it does boil down to that, yes. As you can see from the examples in the article, the syntax is very lightweight and the interpreter is quite "smart". You can compare it to the spark view engine and see the differences between the three. 回答2: It all boils down to syntax in your webpage view , but ASPX and Razor are pretty different view

how to pass a razor value to a jquery function, in an mvc view

我们两清 提交于 2019-12-17 18:28:04
问题 So I'm trying to pass a parameter to a javascript function using the razor '@' notation (in an MVC-4 View) but I'm getting Syntax error: "Unterminated string constant" Is there another way I should be writing this? @foreach (var item in Model) { ... <input type="button" value="Assign" onclick="AssignButtonClicked('@item.ID')" /> } I've used the same syntax as this answer https://stackoverflow.com/a/5179316/1662619 Edit: It's just a syntax error, the functionality still works 回答1: If you can

The difference between Html.Action and Html.RenderAction

不想你离开。 提交于 2019-12-17 18:25:24
问题 I've been trying to figure out the difference between RenderAction and Action. I don't know if I'm so concerned about the differences at this point, as to why I can't get RenderAction to work. From what I can tell, I'm passing in the correct parameters. The overload I'm using seems to be the same for both: @Html.RenderAction(Action, Controller, Route) @Html.Action("Breadcrumb", "Navigation", new {SeoUrl = Model.CarlineBucket.SEOURLName}) @Html.RenderAction("Breadcrumb", "Navigation", new

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

纵然是瞬间 提交于 2019-12-17 18:02:54
问题 I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works

Modifying MVC 3 ViewBag in a partial view does not persist to the _Layout.cshtml

左心房为你撑大大i 提交于 2019-12-17 18:02:05
问题 I am using MVC 3 with the Razor view engine. I want to set some values in the ViewBag inside a Partial View and want retrieve those values in my _Layout.cshtml. For example, when you setup a default ASP.NET MVC 3 project you get a _Layout.cshtml file in the "/Views/Shared" folder. In that _Layout.cshtml the Page Title is set like this: <title>@ViewBag.PageTitle</title> Then in "/Views/Home/About.cshtml" view the contents of the ViewBag are modified: @{ ViewBag.Title = "About Us"; } This works

Using site root relative links in Razor

六眼飞鱼酱① 提交于 2019-12-17 17:53:29
问题 I have a website that is working fine with Razor (C#) all the coding is working properly when I use my local testing (WebMatrix IIS). When I put it "online" on my server the website is not at the root of the site it self For example: http:// intranet.mycompany.com/inform That's basically the "root" of my folder structure so all my folders starts from there (css file default.cshtml... and so on) My "_PageStart.cshtml" sees it properly cause when I access my site from the link http://intranet

ASP.NET MVC Razor Concatenation

穿精又带淫゛_ 提交于 2019-12-17 17:34:01
问题 I'm trying the render an HTML list that looks like the following, using the Razor view engine: <ul> <li id="item_1">Item 1</li> <li id="item_2">Item 2</li> </ul> The code that I am attempting to use to render this list is: <ul> @foreach (var item in Model.TheItems) { <li id="item_@item.TheItemId">Item @item.TheItemId</li> } </ul> The parser is choking, because it thinks that that everything to the right of the underscore in the id attribute is plain text and should not be parsed. I'm

There's no @Html.Button !

末鹿安然 提交于 2019-12-17 17:33:58
问题 this is weird. I see references out there for @Html.Button() but when I type that Intellisense doesn't find such a helper... there's dropdownlist, hidden, editors, et cetera, but no button! what's up with that? 回答1: public static class HtmlButtonExtension { public static MvcHtmlString Button(this HtmlHelper helper, string innerHtml, object htmlAttributes) { return Button(helper, innerHtml, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes) ); } public static MvcHtmlString Button(this

How to use razor engine for email templating with image src

人盡茶涼 提交于 2019-12-17 16:37:27
问题 I've found this link on how to using Razor Engine for email templates in asp.net and it worked great. But I've tried to have a logo in the email template with an image. Something like this: EmailTemplate.cshtml (this by the way is a strongly-type view) <html> <body> <img src="logo.jpg" /> </body> </html> and when I try to submit it on email, it seems that the image path was not read, it only rendered an X in the content. I'm thinking to pass the image path as part of the Model but it seems

Multiple checkboxes in razor (using foreach)

时光总嘲笑我的痴心妄想 提交于 2019-12-17 16:37:22
问题 I have a problem and I can't find solution. I'm using Razor and it is my VieModel class. public class GroupToExport { public GroupToExport() { ToExport = false; } [DisplayName("Export")] public bool ToExport { get; set; } public Group Group { get; set; } } public class GroupsToExport { public GroupsToExport() { //refill list } public List<GroupToExport> ExportingGroups { get; set; } } View: @using (Html.BeginForm("Export", "ElmahGroup", FormMethod.Post, new { id = "toExportForm" })) { //some