MVC :: ActionFilter Returning To View On Handled Error
Oct 13, 2010
I have a action filter:
[Code]....
Once the action filter handles the validation, instead of redirecting to another pages is it possible just to return the view associated with the action with the updated modelstate? Basically this is to handle business validation exceptions thrown by the business layer in a generic way.
I am trying to make ActionFilter which redirects banned users to /Error/NoAccess site, so I have ActionFilter:
[Code]....
Before each public class xxxxxxController : Controller I use [NoBannedUsersActionFilter]. But for example on website /Account/LogOff I have error: 'Server cannot modify cookies after HTTP headers have been sent.' and VisualStudio shows me AccountModel.css file and this method:
I've written a View (form) that has a section with two radio buttons and a blank <DIV> block that will dynamically be updated. When one radio button is clicked, a <DIV> on the page is updated with fields specific to that radio button option. When the other radio button is clicked, the <DIV> on the page is updated with fields specific to that radio button option. To determine what content gets displayed when a radio option is selected, I call a JavaScript function and set the content appropriately using jQuery. Pretty easy so far. Let's assume that the User has toggled the radio buttons and filled in some data. Further down in the form, the User has entered an invalid e-mail address. When the User submits the View, the ModelState is invalid. If it is invalid, I return the View.
[Code]....
Problem is, when the View is returned, some of the form fields (that are static) are in place. However, the <DIV> that was previously updated based on User radio button selections is reset to its original state. When we return a View because of an invalid Model State, is MVC smart enough to return the View in it's modified state (in this case, with the modified DIV and dynamically added content)?
I have a gridview in an update panel which is declared in an ASPX page, and bound to a SQLDataSource in code. The gridview's 'allowsorting' attribute is set to true, and because it is bound to a SQLDataSource, I expect the sorting to be automatically handled.
Yet I am getting the "Message: Sys.WebForms.PageRequestManagerServerErrorException: The GridView 'grdStatusItems' fired event Sorting which wasn't handled" error. I am using Visual Studio 2008, IE8, IIS7. What am I doing wrong? I have done anextensive search for this error, but it seems in most cases where this error occurs, the people are not using a SQLDatasource, so have to handle the sorting event themselves. Is this the case here? Here is the updatepanel and gridview declaration in the aspx file:
I have a partial view (an ascx page (see below)) that is used on every page on my site. Its basically a form, when the user hits submit I need it to call a procedure in one of my controllers and then return the page the user was on.
[Code]....
Public Function TalkToUs(ByVal customer As Customers) As PartialViewResult
What i would like to accomplish is that a partiel view contains a form. This form is posted using JQuery $.post. After a successfull post javascript picks up the result and uses JQuery's html() method to fill a container with the result.
However now I don't want to return the Partial View, but a JSON object containing that partial view and some other object (Success -> bool in this case).
I tried it with the following code:
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(int id, Item item) { if (ModelState.IsValid) { try {
[Code].....
However I don't get the HTML in this JSON object and can't use html() to show the result. I tried using this method to render the partial as Html and send that. However this fails on the RenderControl(tw) method with a: The method or operation is not implemented.
I'm building an ASP.NET MVC site where I want one of the Views I return to be automatically scroll to a certain point.The part of the site where I want this to occur works sort of like a forum - there are "threads" that contain "posts". A user can either browse to the whole paginated thread or can browse to a specific post, using its ID. When a user browses to a specific post, I want to show the regular thread interface, then browse to the page that the post is on and scroll down to the post.
Is it possible to somehow automatically scroll down to a certain point when returning a View from an action in an ASP.NET MVC site? If so, how do I do this?NOTE: One solution to this problem that I've found is how Stack Overflow and the other Stack Exchange sites do it: each answer to a question can be linked to by adding #ID to the URL. If it's impossible to automatically scroll down when returning a View, I would implement this instead, but I don't understand how to use such an approach when there are multiple pages and the post in question isn't on the current page.UPDATE:Based on Chris' answer, I'm currently planning to implement it with the URL looking like this: example.com/forum/[ForumID]/thread/[ThreadID]/post/[PostID]#[PostID]. In my Action, I figure out what page of the Thread the Post is on, and then I return all the Posts from that page to the View.However, I noticed something special in how Stack Overflow solves this problem. Try going to: http://meta.stackoverflow.com/questions/57170 - it ends up sending you to http://meta.stackoverflow.com/questions/57155/gravatar-bugs-and-improvements-in-chat/57170#57170.
I have two custom ActionFilters on an action. In first of the actionfilters, I have an redirect performed if a condition is not met (classic authorization). And in another I have an redirect performed if another condition is not met (say role checking). But I do not want to continue to the second actionFilter if the first one is not met. How to do this?
I'm having troubles remembering how to grab the list view's state, or page, so that when you leave the list, you can return to the list view page you left on. I have a data pager, and I have hyplerlinks for items in the list view that take you to a file upload or file delete page, and then returns to the list view. It returns to the list view's initial state (first page).
I've got and SqlDataSource bound to a GridView, and I'd like to return the value of one of the fields from the SqlDataSource during GridView.RowCreated (I think). At the same time, one of the fields I'm returning to the GridView has a Null value, which I'm cool with, but Runtime is complaining about it so how can I get around errors relating to Null values in my tables?
When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined.I mean assuming I have a view like this
CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.
var foos = myDB.FilteredFoos.Include("Bar").ToList(); foreach (Foo foo in foos) { ...
I am using Actionfilter to globally filter our HTML comments from all action methods and in all controllers. It simply overrides OnActionExecuting and runs the response through a regex to filter the comments. I am also using RenderAction to render some more complicated widgets in my website. There is no caching in place, I just use Renderactionto keep my code as simple possible.
When calling RenderAction from within a Razor View, I get an error message telling me that "Filtering is not allowed". The problem does not occur when calling RenderAction from within an aspx View. It only occurs when calling RenderAction from within a Razor View. In case it matters: the view being rendered is implemented with ASPX. Is this a bug or a known limitation?
I've got this ActionFilter, and it's suppose to end the connection immediately and return a 401 Unauthroized:
public class SignInRequired : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext)[code]....
I learned how you can cancel the action from executing by setting 'context.Result = new EmptyResult()` here, but I'm not sure if this is the best way to flush the response and close the connection.
My Original Issue here:Help! I've got repository access in my MVC master page! Refactor time!What originated as a re factoring job to improve performance has revealed new issues. If I should keep this in my original question - feel free to delete this one, and rename the old one to something more relevant. I'm using an ActionFilter applied to a base controller to load some user-customized settings. My issue is that I save these settings in the filterContext.Controller.ViewData object but its coming through as null on my master page. Here is the relevant code:
Action Filter [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class StoreSettingsActionFilter : ActionFilterAttribute
I'm using ASP.Net and whenever I create a script file or try to include a script file like jQuery they aren't working. I am doing just a regular localhost server and none of the scripts are working. Upon further examination using firebug I look at whats being referenced in those scripts and it shows html code for a 404 error. I know the scripts and files are there and I can navigate directly to them in the browser but for some reason I can't reference them in my page.
I am trying to deploy a wcf service. I have created a simple service, basically I have created a new wcf service and tried to deploy it however I get this error
The type 'WCF_Application.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I am trying to deploy my service to a subdomain like https://services.mydomain.com/business
Im trying use a storedprocedure where depending on the status of the room if ='Vacant' And checkIn =date and the result will be put in a gridview, but i kept returning an error that says, "Conversion failed when convertng datetime from character string". Heres the code.
We have a web project that contain its business methods in a class library project called "Bll.dll" some methods of Bll.dll return List<> ... from a source - that i don't remember now - told that returning Collection<> is better than returning List<> Is it a valid ? Note that i don't make any process on values returned from BLL methods .. just view it in a web page
when I'm building a menu in a view I get following error when code reaches <% Next item%> :
System.InvalidOperationException was unhandled by user code
Message=The value of a property that is part of an object's key does not match the corresponding property value stored in the ObjectContext. This can occur if properties that are part of the key return inconsistent or incorrect values or if DetectChanges is not called after changes are made to a property that is part of the key.
Source=System.Data.Entity
My view: (its a userview)
[Code]....
My Model [Code]....
My Datasource [Code]....
I use this way of looping frequent the only thing is that this is that this entity has a view as source and not a table, so I think it has to be related with that.