logo
down
shadow

ViewBag data coming from ActionFilter is persisting in session even after database


ViewBag data coming from ActionFilter is persisting in session even after database

By : UN_observer
Date : November 20 2020, 03:01 PM
around this issue Just in case I'm leaving this as an answer. Like @NightOwl888 suggested, I have to dispose of the context. in the action filter
code :
public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        //Remove domain\ from windows authenticated user. 
        using (CrewLogContext db2 = new CrewLogContext())
        {
            var currentAppUser = HttpContext.Current.User.Identity.Name.Split('\\')[1];

            //Get user from db. 
            var appUser = db2.AppUsers.Where(i => i.Id == currentAppUser).Single();
            var currentAppUserLocation = appUser.LocationID;
            //get IsAdmin flag. 
            //TODO not updating in VIEW
            bool currentAppUserIsAdmin = appUser.IsAdmin;

            //department related to user. 
            //TODO not updating in VIEW
            var departments = appUser.Departments.ToList();
            filterContext.Controller.ViewBag.AppUserDepartments = new SelectList(departments, "Id", "Name");

            //Flag tells me if current user is ADMIN

            filterContext.Controller.ViewBag.AppUserIsAdmin = currentAppUserIsAdmin;
            filterContext.Controller.ViewBag.AppUserLocation = currentAppUserLocation;
        }
    }


Share : facebook icon twitter icon
Session for single value data is getting from database and for double value data is not coming

Session for single value data is getting from database and for double value data is not coming


By : Marcel Gremmé
Date : March 29 2020, 07:55 AM
To fix the issue you can do This is my code , Its because of this:
code :
using (SqlCommand cmd = new SqlCommand("select * from Products where cast(ProductID as nvarchar(100)) in ('" + Session["Products"] + "')", con))
select * from Products where cast(ProductID as nvarchar(100)) in ('1,2')
select * from Products where cast(ProductID as nvarchar(100)) in ('1','2')
select * from Products where ProductID  in (1,2)
using (SqlCommand cmd = new SqlCommand("select * from Products where ProductID  in (" + Session['Products'] + ")", con))
 mylabelitems=mylabelitems.Replace(","+code, string.Empty);
sqlalchemy - Data not persisting in database with session.commit()

sqlalchemy - Data not persisting in database with session.commit()


By : user3334385
Date : March 29 2020, 07:55 AM
wish of those help I am using PostGreSQL with sqlalchemy. I am relatively new to databases, and brand new to sqlalchemy. I currently have a simple database that contains columns for a githash (primary key), a committer, and a date. ,
data is not persisting in the database between sessions,
code :
def __init_db(self):
    # ... snip ...
    Base.metadata.drop_all(engine)
    #             ^^^^^^^^
    Base.metadata.create_all(engine)
Data I pass from ActionFilter via ViewBag not accessible in View

Data I pass from ActionFilter via ViewBag not accessible in View


By : Wilfred van der Meer
Date : March 29 2020, 07:55 AM
it fixes the issue There is a ViewBag property on the ViewResult where you can set the viewBag items you want to pass to the view. You can set a dynamic object as the value.
code :
filterContext.Result = new ViewResult
                          {
                             ViewName = "~/Views/Shared/Info.cshtml" ,
                             ViewBag= { Message="SS",Title="Hi title"}
                          };
How Can I get Viewbag.Title data in ActionFilter?

How Can I get Viewbag.Title data in ActionFilter?


By : Pedro Henrique
Date : March 29 2020, 07:55 AM
it helps some times I have created ActionFilter in MVC that converts view content to JSON and I want to get the ViewBag.Title parameter contained in the view in the OnResultExecuted method?.how can I get the parameter which I want ? , try this:
code :
filterContext.Controller.ViewBag.tilte= "Hello";
Swift Core Data: Data not persisting between session. context.save() works for the session only

Swift Core Data: Data not persisting between session. context.save() works for the session only


By : Gao Huang
Date : March 29 2020, 07:55 AM
hop of those help? So the problem was batch delete using NSBatchDeleteRequest. I was performing same code for multiple type of NSManagedObjectContext, and all are sub-classes of a single NSManagedObjectContext. So that might be the issue.
When I perform fetch-all-and-delete-in-loop, everything works fine, i.e entities are getting stored. But when I use NSBatchDeleteRequest to delete all at once, the entities that are inserted before the batch-delete operation of the next type of NSManagedObjectContext are getting deleted.
Related Posts Related Posts :
  • ASP.NET MVC Html.BeginForm in WebGrid column
  • I need to set value of my ComboBox depending on selection of other ComboBox
  • How to get a result from a stored procedure as value?
  • Can I pass a ValueTuple to a method that requires a generic type and still maintain the member variables?
  • Testing eager-loading scenarios with Effort.EF6
  • Visual studio breaks on exception that IS handled with unhandled exception dialog
  • Cannot get property of class(ASP.NET MVC)
  • NUnit assertions in production code
  • Bug in SSRS CreateFolder C# command?
  • Convert web form content to PDF using c# in asp.net web forms
  • Web Application publishing failed - Visual Studio - C# - ASP.NET
  • How to encode IP for GET request in api in .NET
  • Access class item generated from xml using xsd.exe
  • Is there a shortcut to explicit named paramers when I call a method in C# for VisualStudio 2017?
  • Sorting datatables in a dataset with the datatable.name
  • Datagridview multilpe links
  • Correct pattern for exposing available actions
  • Local web application accepts numbers with comma and published does not
  • How to read an xml file using xmldataprovider in wpf C#
  • Windows service and Entity Framework
  • Visual Studio 2017 Docker support not available for ASP.Net Core Angular or React projects
  • Datacontext models with join
  • WPF: Increased window size decreases performance
  • Handling bad CSV records in CsvHelper
  • C# Displays file icons in asp.net on GridView nested
  • is there a way to get the file names which need to be updated if TFS status.Numoperations != 0?
  • Headless Firefox in Selenium C#
  • How do I start a .exe with a json string as parameter correctly?
  • StreamContent not loaded to the end
  • HAP parses formatting in HTML documents
  • repeat and count a loop in an unordered sequence in C#
  • Redundant Casting in Visual studio
  • Lost references in Visual Studio 2017 solution
  • Is there a way to add two numbers using a private constructor in C#
  • Is it possible to execute multiple SSH commands from a single login session with SSH.NET?
  • How can I get NHibernate to map to a Tuple or Class?
  • MVC 5 C# Window Authentication pop up when I navigate to a certain area
  • Mongo C# driver toJson() DateTime
  • Coprime integers
  • What is the purpose with files ending with *CS.cs in Xamarin Forms projects?
  • MVC5 / Entity | Update/Create Complex Model
  • How to return auto increment ID from SQL using Petapoco ORM in .NET MVC
  • Create new web app offline c# using Visual Studio
  • How many times is ordered the IEnumerable in this case?
  • C# error when update database 2008 to sql 2016
  • How to insert string in multiple continuous pattern in windows c#
  • How to send temp data from Partial View to its parent View
  • C# encapsulation when getting updates from asynchronous method
  • Asp net core Content Security Policy implementation
  • @Html.DropDownList() Placeholder as Disable and Selected
  • Set AM/PM in Material Time Picker WPF
  • Ninject passing reference in constructor
  • C# Entity Framework text SQL query wrapper
  • Core 2.0 MVC - AD Group Authorization for logging
  • Decentralized NLog Target per Http request
  • How to use x:Object and when?
  • Displays file icons in asp.net on GridView
  • How do I avoid two (or more) threads that work on a table at the same time to not work on same row?
  • Add xml attribute for property in DB First
  • How do i execute 2 sql queries by clicking a button [C#]
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org