razor

User.Identity.Name is returning UserName instead of Name

那年仲夏 提交于 2020-01-04 05:45:36
问题 I want to display Name of a user instead of UserName in navbar that is in _LoginPartial Currently I'm using User.Identity.GetUserName() for userName but now I want to display Name of the current user. _LoginPartial is called by the Startup.Auth.cs so I can't run the query on the backend and get the Name of my user so I can only use built-in functions which can run by razor in view. I have tried all of them but they all are giving me username instead of name of the user. <small>@System

Html.RenderPartial does not produce a value

六眼飞鱼酱① 提交于 2020-01-04 04:11:15
问题 Good day, all. I know that this is a pretty basic question in terms of MVC, but I can not for the life of me get @Html.RenderPartial to not give me errors. I am using VB.NET, and Razor. Most examples that I have found online are written in c#, which isn't hard for me to convert, but this simple one has got me stumped. This is in my Index view, that is being rendered by the _Layout.vbhtml: @Section MixPage @Html.RenderPartial("_MixScreen", ViewData.Model) End Section The above expression does

Suddenly getting “…'Layout' does not exist in current context” in _ViewStart.cshtml

微笑、不失礼 提交于 2020-01-04 04:08:12
问题 I have a MVC 3 project that I deployed about a year ago then moved on. The client asked for some mods and I re-opened the solution to find the red squiggly line error in the _ViewStart.cshtml file. I fixed the assembly System.Web.MVC version issue (3.0.0.0->3.0.0.1), but I have no idea why this is happening. I'm also getting the same red squiggly with @RenderBody() in the _Layout_.cshtml file. Nothing has been changed and it compiled and ran fine last I looked. I suspect Windows update may be

'$' is undefined. How to use jQuery 2.0.1 in empty ASP.NET MVC 4 project?

旧巷老猫 提交于 2020-01-04 04:00:49
问题 I already take a look at: '$' is undefined, but it did not solve my problem; that´s why I open another thread. This is what I did... I created a new solution using Visual Studio 2012 and added an empty ASP.NET MVC 4 project. I added a controller class, defined a default Index action method and let Resharper create the view for it. The project has the following structure: root/ Controllers/ SampleController.cs Models/ Views/ Sample/ Index.cshtml Shared/ Layout.cshtml Scripts/ jquery-2.0.1.js

How to insert “File1.cshtml” into a section in main view

[亡魂溺海] 提交于 2020-01-04 02:50:06
问题 Ok, im probably doing this wrong... But in my main _Layout I have this: <div id="navigation"> @RenderSection("Navigation") </div> which points to this in my Index.cshtml view: @section Navigation{ <-- Need this to point to Views/Shared/Navigation.cshtml --> } But I don't want to have a huge file with all my code in it, so I need to know how to point to a file called "Navigation.cshtml" inside of this section - basically so I have all my sections in separate, independent files. I tried just

Writing JSON via MVC and RAZOR

霸气de小男生 提交于 2020-01-04 02:41:45
问题 I have an ASP.NET MVC 4 app. This app has a view with a block of javascript in the footer. I'm using the RAZOR view engine. I'm trying to figure out how to convert my result set into a JSON array. Currently, I'm doing the following: <script type="text/javascript"> @for (int i=0; i<ViewBag.States.Count; i++) { <text> { id: @Html.Raw(ViewBag.States[i]["ID"], name: \"" + ViewBag.States[i]["Name"] + "\"}") </text> if (i < (ViewBag.States.Count - 1)) { <text>,</text> } } </script> This approach

Call one Razor helper from another

懵懂的女人 提交于 2020-01-03 21:09:30
问题 I need to create the second overload of Razor helper and want to call one helper from another (with some specific parameters). Is there any way to implement it? 回答1: Sure: using System.Web.Mvc; using System.Web.Mvc.Html; public static class ActionLinkExtensions { public static IHtmlString MyActionLink(this HtmlHelper html) { // call the base ActionLink helper: return html.ActionLink("some text", "someAction"); } } and then in your view: @Html.MyActionLink() If you are talking about @helper

Kendo UI Grid - Show row number

半世苍凉 提交于 2020-01-03 18:35:15
问题 How do I show the row number in a Kendo UI Grid? The code I have is not working. The page displays the column but it's empty. @{int counter = 1;} @(Html.Kendo().Grid<QueueViewModel>() .Name("Queue") .Columns(columns => { columns.Template(@<text><span>@counter @{ counter++; }</span></text>).Title("#"); }) .DataSource(dataSource => dataSource .Ajax() .PageSize(10) .Read(read => read.Action("GetOpenQueue", "DataSource", new { GeneralQueue = true }) )) 回答1: Do this: @{ int counter = 1; } @(Html

Disable editing in kendo grid

谁都会走 提交于 2020-01-03 17:18:05
问题 I am trying make the an editable grid to uneditable depend on conditions. I have tried in jquery as below var $grid = &("#gridName").data("kendogrid"); Var model = $grid.datasource.at(1); if(model) model.field["cell"].editable = false; but here the 'model' is getting undefined. also tried $grid.data() and then looping through the grid, but the cells are not getting uneditable they are still editable. Can anyone please let me know how can I make this work. 回答1: You have some typographic errors

Strongly typed Razor views in dynamically loaded assembly don't compile at runtime

浪尽此生 提交于 2020-01-03 17:07:53
问题 I have a MVC3 Area in an assembly that is dynamically loaded with MEF. If I use the Webforms view engine with strongly typed views, everything works fine. If I use the Razor view engine with a dynamic model, it works fine too. But if I use a strongly typed Razor view , the view compilation fail at runtime. The problem is that the dynamically loaded assembly is not in the list of referenced assemblies passed to the C# compiler. The generated C# code looks like this: namespace ASP { using