How To Hide Specific Elements On A Razor View Based On Security Without Logic In View

Apr 4, 2011

I have looked all over for elegant solutions to this not so age-old question. How can I lock down form elements within an ASP.Net MVC View, without adding if...then logic all over the place? Ideally the BaseController, either from OnAuthorization, or OnResultExecultion, would check the rendering form elements and hide/not render them based on role and scope. Another approach I have considered is writing some sort of custom attributes, so as to stay consistent with how how we lock down ActionResults with [Authorize]. Is this even possible without passing a list of hidden objects to the view and putting if's all over? Other background info: We will have a database that will tell us at execution time (based on user role/scope) what elements will be hidden. We are using MVC3 with Razor Viewengine. We're utilizing a BaseController where any of the Controller methods can be overridden.

View 1 Replies


Similar Messages:

Hide Non-Displayed ASP Elements In Design View?

Apr 23, 2010

Is there a way to prevent non-displayed elements from appearing in the ASPX Design View editor?By "non-displayed elements", I mean the background elements (Managers, DataSources, Validators, etc) that show up as grey boxes containing the type and id.If I have several of those at the top of the page, I can't see much of the preview of my page.

View 1 Replies

Security :: Accessing Elements Within Login View?

Mar 11, 2010

I have the following code for my page:

[Code]....

And the following .cs file associated with it:

[Code]....

I would like to be able to do the following in the .cs file for this page:

#1. Initially "Submit News" is disabled. The admin must click "Preview News" which will update the newslabel temporarily and also enable the "Submit News" button.

#2. When the "Submit News" button is clicked, the news.txt file should be opened and whatever content is currently in the newslabel.Text will be written to news.txt. The news will then be updated for anyone to see.

Right now, if I try to do "submitnews.Enabled = false;" is does not let me because it thinks that submitnews is not in the current context. Basically I need to know how to access elements that are within a <asp:LoginView> area.

View 2 Replies

MVC 3 - Razor - Trying To Use A Partial View For A File Upload In A Create View?

Oct 19, 2010

I am trying to use a partial view for a file upload in a Create View.

Here is my partial view, I removed the submit button, as the view it is rendered in, should activat the form post:

@model dynamic

View 1 Replies

MVC 2 Technique To Hide A Part Of A View Based On User Permissions?

Aug 30, 2010

What's the best technique to hide part of a view depending of the credentials of the user?

To explain my self little better and as example i have the following code in my view:

<%= this.Model.Name %> <%=Html.ActionLink("Edit",....)%>

And i would like to hide the edit button for those that aren't administrators for instance...

Could you give me a hand?

View 2 Replies

MVC :: Filtering Data In Partial View Based On Datepicker On View?

Mar 6, 2011

I have added a jquery datepicker on my MVC view. This view has a partial view. I need to filter my partial view based on the datepicker's selected date. I need to show buttons on partial view based on the date.

I have added partial view like this:

div id="dvGames" class="cornerdate1"> % Html.RenderPartial("Partial3"); %>
/div>

View 5 Replies

MVC :: Partial View Based On Current View's Data?

Nov 10, 2010

I have a view that displays all the records of my Roles table. I want to be able to click a Role record and have a list of users that pertain to that role displayed to the right of the Roles list. I'm sure I need to use a view model for this so I can get two sets of models in one view, but I'm not sure how to set up the view model.

Controller code:

[Code]....

Repository (userRep) code:

[Code]....

I can just as easily get the full user list with return db.Users;

So what method needs added to my repository and how should my view model look?

View 6 Replies

Security :: How To Find Out If The Current User Is Elligible To View An URL Based On Role Provider

Aug 17, 2010

I want to execute some logic if the Logged in User can view a page "~/MyPage.aspx". IF the logged in user should be elligible to view the page is determined by the role based security I configured in the web.config file. There are many methods to find out if the user is in role XXX or not. But I did not find any method to find out if the user can view a page or not ahead of transferring the user to that page. Maybe I will hide a link to a specific page to the logged in user if the user is not elligible to view that page if I know the technique i am asking here to know.

View 1 Replies

Repeater Conditional View With No Data Logic?

Mar 21, 2011

on my repeater i builed a table and want to show a colum just for user that is in role admin.i need to remove the column in the HeaderTemplate and in ItemTemplate.i could use data logic and add a db column that will be boolean, but then i need to send to the SP the user role.

<asp:Repeater ID="TemplatesList" runat="server">
<HeaderTemplate>
<table>
<tr>
<th>
[code]...

View 1 Replies

MVC :: Calling Business Logic In Model From Submit Tag In View?

Jun 30, 2010

Currently I am working on a project at work that deals with MVC. I have never used MVC before, only dealt a little with ASP with VB, and that's it. I've dabbled in HTML but not much. I don't currently have the money for a book, so I'm using this forum. So there's a lot of jargon I may not pick up on or may ask a lot of questions, so please bare with me.Anyways here's what I would like to do, or understand. We're using ASP.NET Membership Security (not sure if that's what it's actually called) for passwords and accounts. My issue is that I've been working on other projects while the rest of my team has been working on this, so they know more about it than I do. And I don't want to take too long to understand it, but I have to find the best way to make sure the following doesn't happen:

1) When changing a password, it can't be within the last 10 passwords used for that user.2) When creating/changing a password, it cannot have dictionary words, names, phone numbers or personal data within it.3) The password must be a minimum of 16 characters.Number 3 is rather easy and completed I believe. However, 1 and 2 prove tenuous. We want to store the previous passwords hashed and we were going to save the salt used. However, I'm beginning to think that with the Membership class you can't specify the salt to hash a password. Is there a way to de-hash a password? We do not want to store the passwords as plaintext, so that is out of the question.I believe the best order (for 1 and 2) is to do 2 first (before it's hashed) and then 1. For two, I need to know how to call a function in the Model code from a <submit> tag in the View code. I've done a little research online but thought I'd ask and see if it gets answered while I'm looking for the answer.

In general, my questions are:1) How do I call a function in the ****Model.cs from a <submit> tag in the *******.aspx?2) What's the best way to compare previous passwords that are hashed? 3) If I know the salt, can I de-hash a password? (I believe the answer to this is no.)4) Can I specify the salt to hash a password? (I believe the answer to this is no.)5) If #3 and #4 are no, then should I do encryption instead of hashing?Details: MVC2, C#, Membership.

View: Account/ChangePassword.aspx

[Code]....

Model: AccountModel.cs

View 16 Replies

Security :: Select User View Only Noticesselect User View Only Logsselect User View Only Newsetc?

Feb 14, 2011

have a web in which there are different areas i have a 1 admin which manage all things like news, Events, Notices, Logs, Forums, Publications etc.........i want assign user rights that select user view only Noticesselect user view only Logsselect user view only Newsetc....

View 7 Replies

Is It Possible To Use Razor View Engine Outside

Sep 2, 2010

If I look at the Razor View Engine, then I see a very nice and concise syntax that is not particularly tied to generating html. So I wonder, how easy would it be to use the engine outside asp.net in a "normal" .net environment for example to generate text, code,...

View 3 Replies

MVC :: How To Translate A View To Razor

Nov 15, 2010

I want to change my project to use razor syntax. How do I translate a view to razor syntax?

also, when I add a new view, I don't see an option for the view engine to use. Is there one?

View 4 Replies

MVC :: Get Row Count In Razor View?

Feb 21, 2011

I have a Razor view of type Joke. Here is the relationship between the Entity Joke and the Entity Rating:

I have done eager loading in my HomeController to get the Ratings from the Database. But I seem to be unable to get a count of the ratings that belong to a particular joke. Here is the error I get:

PS. You can ignore that <img> code to the right.

View 14 Replies

Web Forms :: Hide Specific Row Cell From GridView Based On Some Condition

Aug 3, 2012

I have a gridview which displays a list of submittted applications with a column that contains an edit link.

<asp:TemplateField HeaderText="Status">
<ItemTemplate>
<asp:LinkButton ID="lnkBtnEdit" runat="server" CommandArgument = '<%# Eval("appID")%>' Text = "Edit" OnClick = "editApp" />
</ItemTemplate>
</asp:TemplateField>

I want to hide the link button if the status (value 1 or 0) of the form is set to 1. Here is the code I am trying to use.

Protected Sub gv1_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
'get the cell cell value
Dim status As Integer

[code]....

I think my mistake lies in getting the status value (as it ouputs 0 for every application).

View 1 Replies

MVC :: Migrate 2 Project To 3 - Razor View

Sep 8, 2010

I have an application which has been built in MVC 2.0. I need to upgrade it to MVC 3.0 and that too by using Razor CSHTML engine. All the information which I got on the net was for MVC 3.0 Webform engine but nothing much for migrating to Razor.

View 37 Replies

MVC :: How To Set A Break Point In A Razor View

Nov 11, 2010

I can't seem to figure out how to set a breakpoint in a Razor view. I understand why that might seem a little weird and may be difficult since a cshtml file is a combination of html and then c# code, but I can step into it. The ability to step into it makes it seem like I should be able to set a breakpoint. Am I missing how to do this or is this not possible in the RC? If not any plans to add this before RTM or in the future?

View 3 Replies

MVC :: Unit Testing Razor View?

Mar 3, 2011

How can I render a razor view in a Unit Test?When I change for instance a html helper method, I sometimes forget to update all the views which uses that html method. So the view I forgot generates a YSOD.I would like to create unit tests that renders a view and fails if I forgot to make the neccecary updates.

View 2 Replies

MVC :: Unit Test Razor View In 3?

Mar 11, 2011

Is it possible to write unit tests against razor view in MVC 3? If yes, can anyone point me to code sample to unit test a razor view in MVC 3?

View 2 Replies

MVC :: C# Code In Razor View - Right Statement?

Feb 27, 2011

I have this C# code in a Razor view:

@(Html.CheckBoxFor<RazorSamplesWeb.Models.SamplesModel>(i => i.IsActive))

I tried translating it to this:

@Code Html.CheckBoxFor(Of RazorSamplesWeb.Models.SamplesModel)(Function(i) i.IsActive)End Code

But it's complaining. Why, and what is the right statement?

View 2 Replies

MVC :: Razor - Create Instance Of View?

Oct 12, 2010

In my controller method, I'm trying to create an instance of a View (cshtml file) before I wrap it around an ActionResult and return it.Since there is no "class" for Razor Views to speak off, how does one go about creating an instance of a Razor View?

View 25 Replies

MVC :: 3 Razor Add Script From Partial View

Feb 17, 2011

What is the best way to add javascript at runtime from a view (or partialview)? For example i would like to build a partial view Banner.cshtml that use Banner.Js. Actually i am using a section into layout page but obviusly if i use 3 times the same partial view i have 3 reference to external Js. Is there a "best practice" to include Js from "child" elemnts like partial view in this case?

View 3 Replies

.net - Execute Razor View Dynamically?

Feb 23, 2011

is there a way to execute a razor view dynamically? if i have the view code as a string can i execute it and pass it a model as a parameter for example?

View 1 Replies

Web Forms :: Disable View State / No Business Logic In The Button Click Event?

Apr 19, 2010

I have a textbox control i disabled view state at page and control level.i entered a value in the text box and click a button there is a postback,no business logic in the button click event.The values in the testbox are persisting though i disabled at the control level and page level.

View 5 Replies

Does The Razor View Engine Work For Mono

Nov 21, 2010

I tried searching a bit and didn't find an answer. Does the Razor View Engine work in Mono?

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved