razor

ASP.NET Vnext Tag Helpers for Areas

北城以北 提交于 2020-01-02 00:32:40
问题 I may use <a href='/Area/Controller/action'> </a> in asp.net vnext but just want to know whether we can use tag helpers like <a asp-controller="ControllerName" asp-action="ActionName" asp-area="AreaName"> to redirect to the specific file in the area. Will any one guide me how to redirect to a file in area using tag helpers.? 回答1: Finally I got the answer from the following link which works well. <a asp-route-area="AreaName" asp-controller="ControllerName" asp-action="ActionName"> </a> github

ASP.NET MVC preventing users from direct URL

99封情书 提交于 2020-01-01 19:29:07
问题 So I've created a simple "hello world" in MVC as proof of concept. The index view list some made up records that are followed by the typical "edit", "details", and "delete" ActionLinks. However, depending on which AD group owns the record, I don't render some of those options. So for example, say I'm pulling up 5 records, and I'm a member of an Group\Role that only owns 1 of them. My Index page would look something like... Name Price Foo1 $10.00 Details Foo2 $20.00 Details Foo3 $30.00 Details

ASP .NET MVC 5 Write javascript in View.cshtml file [closed]

一曲冷凌霜 提交于 2020-01-01 19:22:47
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 4 years ago . I'm new to ASP .NET and I am struggling with javascript in MVC. I have a IndexView.cshtml file inside View folder and would like to write a short javascript section inside to move site back to top with a button. It works perfectly in normal html so there is that. Normally a button shows up whenever

Create a helper function that returns Razor @ tags?

我怕爱的太早我们不能终老 提交于 2020-01-01 19:00:13
问题 Struggling to find an answer to my question, as I'm not exactly sure what 'type' a razor tag is. Essentially I want to create a helper that does something along these lines: public static xxxxxxx ScriptTag(this HtmlHelper htmlHelper, string url) { return @<script type="text/javascript" src="@Url.Content("~/" + url)" />; } The reason I want this is that I am implementing the extension methods that are outlined in this post. Basically rather than have to do: @Html.Resource(@<script src="@Url

How to pass data from razor view to controller in mvc3?

懵懂的女人 提交于 2020-01-01 18:09:08
问题 I have a model that I'm using to pass data from my view to my controller but I have some unbound from textboxes and dropdownlists. How can I pass that unbound data from my view back to my controller using ViewData or ViewBag....or something. Thanks! 回答1: Can you give an example? It looks as if you're mixing up your terminology a bit. You don't generally pass data from a view to a controller except via a POST/GET . I'm going to assume that's what you meant. You can get any data into your

pass data-icon attributes in razor html helper

若如初见. 提交于 2020-01-01 14:57:39
问题 I want to following html code using asp.net mvc 3 razor html helper: <input type="text" .... . placeholder="Login" data-icon="user" /> I have try this one: @Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", data-icon = "user" }) or @Html.TextBoxFor(m => m.UserName, new { placeholder = "Login", @data-icon = "user" }) Displayed Error: Invalid anonymous type members declaration. This might due to dash in data-icon not taken as attributes. How could I add data-icon attributes in text

Returning razor-parsed Javascript as a ViewResult from a controller

笑着哭i 提交于 2020-01-01 12:37:08
问题 I've successfully created an mvc/razor web application that returns css files that have been parsed by razor. Each time there's a background-image I have a razor snippet that writes the URL prefix to the image file name. The CSS now looks like this: body { background-image: url(@LookupUrl.Image("background.gif")); } Css files now work fine and I've moved onto trying to get javascript .js files to function the same way but these aren't playing ball. The code is identical to the css code and it

Returning razor-parsed Javascript as a ViewResult from a controller

孤人 提交于 2020-01-01 12:37:07
问题 I've successfully created an mvc/razor web application that returns css files that have been parsed by razor. Each time there's a background-image I have a razor snippet that writes the URL prefix to the image file name. The CSS now looks like this: body { background-image: url(@LookupUrl.Image("background.gif")); } Css files now work fine and I've moved onto trying to get javascript .js files to function the same way but these aren't playing ball. The code is identical to the css code and it

MVC @Html.DropDownList Getting Error with SelectList in ViewBag

戏子无情 提交于 2020-01-01 12:11:18
问题 I have a list which I created in the controller: var PayList = new[] { new ListEntry { Id = 1, Name = "" }, new ListEntry { Id = 2, Name = "Yes" }, new ListEntry { Id = 3, Name = "No" } }; ViewBag.PayList = new SelectList(PayList, "Id", "Name"); In the view I have the following: @Html.DropDownList("Pay", new SelectList(ViewBag.PayList,"Id","Name")) When I try to display it, it says the following: DataBinding: 'System.Web.Mvc.SelectListItem' does not contain a property with the name 'Id'. Not

Extend A View With Thymeleaf

牧云@^-^@ 提交于 2020-01-01 12:01:38
问题 is it possible extend a shared view with thymeleaf ? I saw that is possible use framents but is not what I want. Instead I want something similar to .NET MVC, with something like @RenderBody() and another view that extend the shared view by including the shared view. 回答1: You can use the Thymeleaf Layout Dialect to extend a view. Layout page <html xmlns="http://www.w3.org/1999/xhtml" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> ... <body layout:fragment="body"> ... </body> </html