Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6887517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:53:40+00:00 2026-05-27T05:53:40+00:00

A novice to asp.net and mvc3. I am learning by setting myself challenges/developing an

  • 0

A novice to asp.net and mvc3. I am learning by setting myself challenges/developing an application. I tag all record tables where users interact with ProviderUserKey. Now I want to be able to restrict users logged in to be able to edit or delete their own records only but administrators can edit or delete any. I have been using scaffolding to generate controllers and views etc. for eg code for editing`// POST: /Post/Edit/5

    [HttpPost]
    public ActionResult Edit(PJpost pjpost)
    {
        if (ModelState.IsValid)
        {
            db.Entry(pjpost).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(pjpost);
    }`

Any help will be highly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:53:41+00:00Added an answer on May 27, 2026 at 5:53 am

    If you have a generic Edit method/action and you would like to keep it that way, I would add a method in your controller somethink like ValidateOwnership(record). This method would need to verify if CurrentUser’s ID is matching the one on the record and if user is a member of particular role – that can be done with RoleManager class. Method would return true/false.
    When you got it ready just put the call to the method in your code after ModelState validation. It would look like this

    [HttpPost]
    public ActionResult Edit(PJpost pjpost)
    {
        if (ModelState.IsValid)
        {
          if(IsOwnershipValid(pjpost){
              db.Entry(pjpost).State = EntityState.Modified;
              db.SaveChanges();
              return RedirectToAction("Index");
            }
           else {
               ModelState.AddModelError("ERROR","You're not allowed to do that");
               return View(pjpost);
            }
        }
        return View(pjpost);
    }
    

    EDIT :
    So the OwnershipValidation could look like this :

    public bool ValidateOwnership(Pjpost pjpost) { 
        if (pjpost.MemUID == Membership.GetUser().ProviderUserKey.ToString()) 
        { 
        return true; 
        } 
        else 
        { 
        return false; 
        } 
    } 
    

    I hope this is what you meant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im currently setting up asp.net to accept DELETE http verb in the application. However,
I am converting a web application from asp.net to MVC3 and am trying to
I'm developing my first ASP.NET MVC 3 application and have a couple of jqGrid
I'm an ASP.NET web part novice. I've built a few simple ones using only
With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI
I'm trying to test the Data values that are returned from an ASP.NET MVC3
I'm looking at an asp.net application, i notice that there are assemblies defined into
I am having a 'learning' day and am delving into an ASP.NET solution to
During ASP.NET precompilation of our .NET 3.5 web application, various initialization is performed in
I'm creating a new project, asp.net mvc3 with Razor, and wanting to turn the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.