razor

ASP.NET MVC3 RAZOR: Retrieving Hidden field Attribute value in Controller (using ViewModel)

走远了吗. 提交于 2019-12-13 20:51:19
问题 I have a view that has two buttons(“First” and “Second”) and one hidden field. When user clicks on “First” button, hidden field will be set as the value of “data-myAttribute” attribute in the first button. When user clicks on “Second” button, hidden field will be set as the value of “data-myAttribute” attribute in the second button. Once the hidden field is set, the form need to be submitted. This much is working fine with the following code. Further, I need to be able to see the value of the

Can't get HttpContext.Current.User.Identity to work in my WebMatrix project

本秂侑毒 提交于 2019-12-13 20:29:05
问题 I want to capture the user opening my page in an internal Windows AD network. I think I've tried everything: @{ // other code string user123 = HttpContext.Current.User.Identity; } and also @{ // other code <script> var user123 = HttpContext.Current.User.Identity; </script> } And trying to use that later inside my HTML code. Or passing it as a parameter to a stored procedure inside my razor block. Nothing. Either empty, runtime error, or undefined. Note1: HttpContext is recognized by WebMatrix

For data validation, where to add Html.RenderPartialAsync(“_ValidationScriptsPartial”)?

不想你离开。 提交于 2019-12-13 20:23:29
问题 In my ASP.NET Core 1.1.1 app the model validation is not working. I've noticed that some of the default views (such as login.cshtml , Register.cshtml that were created by VS2017 when the app was created) have the following code at the end. But these default views are in fact partial views. My Views are not partial views, should the following be added to end of my views as well? Or what should I be adding to the end of my views that are not partial views: @section Scripts { @{ await Html

How To Call Controller from Layout Html.Partial

爱⌒轻易说出口 提交于 2019-12-13 20:14:11
问题 I'm working with Asp.net MVC 4, engine razor. I am developing an application and the menu is dynamically created by the user's role UPDATE In my application I need the user to enter their credentials with these recovered data on user role and build the dynamic menu for the role. My main screen is: in my _Layout.cshtml I have this code: @if (Request.IsAuthenticated){ Html.Partial("Menu"); } else { <div class="sectiontitle"> </div> } I create a base controller: public class BaseController :

Hosting the Razor View Engine using a view model

人走茶凉 提交于 2019-12-13 19:58:24
问题 I'd like to use the Razor View Engine outside of ASP.NET MVC to generate HTML for emails, I like the syntax and it seems unnecessary to use another templating engine when I already have Razor in my project. So I looked around and found this guide on how to do it.. http://blog.andrewnurse.net/2010/11/16/HostingRazorOutsideOfASPNetRevisedForMVC3RC.aspx Unfortunately I can't find any way of specifying a view model, which is sad because I would really, really like to have strongly typed views

Cannot get @Ajax.ActionLink to work in a partial view, get “Cannot resolve” error

回眸只為那壹抹淺笑 提交于 2019-12-13 19:44:29
问题 I am using MVC3, ASP.NET 4.5, C#, Razor. I have successfully got the Ajax.ActionLink working from my main page which contains a table and records with each containing a link. The Ajax.ActionLink "replaces" the record in all cells within the element. I use a partial view to do this replacing in: <td>col1</td><td>col2</td> However col1 should retain the Ajax.Actionlink as it will be required again, so my partial view should be: <td>@Ajax.ActionLink("Delete",...)</td><td>col2</td> But I get a

In a Razor view how can I insert the page title without a <?

强颜欢笑 提交于 2019-12-13 19:37:51
问题 In my ASP.NET MVC 3 Razor layout view I want my page title to always be "My Website" and if ViewBag.Title is set I want to append that to the title, using a hyphen as a separator. I want this code to be on a single line This code fails : <title>My Website @if( string.IsNullOrEmpty( ViewBag.Title) == false){ - @ViewBag.Title}</title> With The if block is missing a closing "}" character. Make sure you have a matching "}" character for all the "{" characters within this block, and that none of

Check ViewBag Value is present in javascript

谁都会走 提交于 2019-12-13 19:26:24
问题 I am using razor template and following is the scenario $(function(){ //if (ViewBag.IsCallFunction){ somefunction(); // //do something else }); If a viewBag variable is present, i.e. not null and if it is set to true, then I would like to call some javascript function. How do I do this? 回答1: @{if(ViewBage.somevalue!=null && ViewBage.somevalue=="true") { <script type="text/javascript"> somefunction(); </script> } } but remember this will get called as rendered, as per OP, you can't call it,

Rendering dynamic HTML content into variable in Razor

馋奶兔 提交于 2019-12-13 19:18:57
问题 I want to render dynamic HTML content into a variable to later pass it to a function. The reason is, that I receive the actual content through another platform and I can print it out using an internal function. This function accepts values to put into placeholders. Example: This is my content: {mytable} Blah Now I can set any content on mytable . Good. The content I want to put there is currently the following. @using System.Data @model Dictionary<string, DataView> <table> @foreach (var group

Handling Like and Unlike of an entity in ASP.NET MVC using AJAX

让人想犯罪 __ 提交于 2019-12-13 19:08:55
问题 I have a razor view where the model is an IEnumerable of Product so I am simply listing all of the products in the view using a foreach loop on the Model. Along with each product you can see below that I am showing the count of how many ThumbsUps it has. The final thing I am trying to accomplish is when they click on the link 'Give Thumbs Up' I would like to add a ProductThumbsUp record to the database for the current logged in user. If the user already has given a thumbs up and clicks it