Dynamically generated pop-up modal based on verified user

Can anyone provide guidance on this issue?

I am working on a login screen for two types of users: Suppliers and Admins. I need to implement a popup screen that appears only when a supplier logs in, prompting them to sign a declaration by clicking on a radio button. This step needs to be completed before they can access the backend system. The popup should not show up for admin users.

Answer №1

Are you working with Razor and using Identity for authentication?

If so, check out this helpful answer first:

To retrieve user roles, use the following code snippet:

    var user = await _userManager.FindByNameAsync(User.Identity.Name);
    // Check if any of the found roles are equal to "Supplier"
    bool isSupplier = await _userManager.GetRoles(user.Id).Any(x => x == "Supplier");

You can then add a flag to the model you're passing to the razor view:

public class MyViewModel{

  public IsSupplier { get; set; }
  ...

}

Set

MyViewModel.IsSupplier = isSupplier
based on the previous check. In your razor view, you can use an if statement to determine whether to display an ajax popup:

@if(Model.IsSupplier){
  <!-- Include HTML here for displaying the popup -->
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best approach to enable Amazon Signature 4 presigned URL for Ajax functionality?

After spending nearly 48 hours troubleshooting, I have discovered an issue with generating a presigned URL for listing part of an S3 bucket's contents. The presigned URL works perfectly when pasted into the browser or used in hurl.it. However, when t ...

Modify path and refresh display upon ajax call to node server

Recently, I made the decision to utilize a Node server as a proxy for making API calls to third-party public APIs from my front end. After successfully sending a request to my Node endpoint and then to the third-party API, I received the expected response. ...

Retrieve the current URL using Jquery Ajax when submitting a form

I utilized the code provided by this resource to submit data from a form. The form contains fields for Lastname, Firstname, Mobile, VAT, Address, Streetno, Postcode, Email, and Notes. <form id="request" method="post" autocomplete="off" class="form-hori ...

Breaking down and analyzing XML information

I have data that I need to retrieve from an XML file, split the result, parse it, and display it in an HTML element. Here is a snippet of the XML file: <Root> <Foo> <Bar> <BarType>Green</BarType> &l ...

Real-time communication using Ajax technology in web-based instant messaging applications

I'm curious: Is it feasible to implement a basic Ajax instant messaging system for a popular social network with thousands of users? I am new to this, so I am just curious. What if we checked for new messages every two or three seconds? Revised: Can ...

Can switching to polling data from a SQL database instead of a file in a chat application lead to improved performance?

Currently developing a chat application and considering using a SQL database for it. The challenge is that I've come across conflicting information online regarding the performance of using a DB versus a regular file (such as Text or JSON). User expe ...

Received TypeError: Unable to call reset function - issue clearing input field post ajax request

Having Trouble Clearing Input Fields After AJAX Request: $.ajax({ type: "POST", url: "river_flow.php", data: { username: $("#username").val(), idv:$("#idv").val(), comment: $("#comment").val()}, cache: false, success: function(da ...

Sending the chosen option from a dropdown menu to a php variable prior to form submission

I am currently utilizing the following code (in lightboxform.php) to pass the chosen dropdown value to a php file (edit.php) via ajax, and then return it back (to lightboxform.php) and store it in the desired php variable. However, there seems to be an iss ...

Delete an element once the ajax request is complete

After closing the modal, I noticed that a div element was left behind causing the screen to become unresponsive. <div class="modal-backdrop fade show"></div> I found that removing this element using the console command below fixed the issue: ...

Validate the C# model by cross-referencing data from several Lists

In need of validating a JSON input model by cross-referencing values from one List to another. The specific value in question ranges from 1 to 5 and represents a rating. If there is no match found, an error should be triggered. Here is the code snippet f ...

Having trouble with jQuery.validate.js while using type="button" for AJAX calls in an MVC application

I have come across several questions similar to mine, but I haven't found a solution that fits my situation in MVC, so I am reaching out for help. I am a beginner with MVC and I am utilizing jQuery AJAX to invoke a controller method for data insertio ...

Update the content of the page without reloading images

Is there a way to refresh a webpage on click without refreshing the images, only the text content? Can this be achieved without clearing the cache? I attempted to refresh the entire page with the following JavaScript code: <script> $(".secon ...

Tips for refreshing HTML multiple file upload without reloading the page

I am currently working on a feature that involves counting the number of files uploaded. If more than 10 images are uploaded, I want to clear the input field while keeping everything else in the form intact. Everything was working fine until I encountered ...

Order of execution behavior

I am currently working on a function that, when triggered, will populate the webpage with dynamic tiles. These tiles retrieve data from a remote database through an AJAX request and utilize jQuery 3.0 in the implementation. Function Implementation: funct ...

Issue with Current Code for Reading/Writing Json in C#

Error: error CS0103: The name 'JsonConvert' does not exist in the current context I have tried everything to resolve this issue, including installing the latest version of Newtonsoft and searching through numerous resources for a solution. Despi ...

Is it possible to dynamically load records in real time with the help of PHP and jQuery?

I developed a custom system using PHP that allows users to post status messages, similar to a microblog. The system utilizes a database table structured like this: posts_mst ------------------ post_id_pk post_title post_content date_added Initially, I su ...

Instructions for selecting all checkboxes in an HTML table with just one click

Developing an aspx page with 3 HTML tables, I am dynamically adding checkboxes to each cell. Additionally, I have a checkbox outside each table. When I check this checkbox, I want all checkboxes in the corresponding HTML table to be checked. However, curre ...

Disable reloading when submitting and reset input fields after submission

I am working on developing a website where users can post things and comments without the need to refresh the page. I have encountered some issues while implementing this feature and need some assistance with it. My goal is to allow users to submit comment ...

The trio of Javascript, Ajax, and FormData are

I'm struggling with sending form values to a PHP file. Here's the code I have: <form role="form" id="upload_form" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="formlabel">Title< ...

Requesting data using Ajax with multiple parameters

I have an ajax call that requires adding multiple sets of data. function sssssss(page){ loading_show(); var form2 = document.myform2; var dataString1 = $(form2).serialize(); ...