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 8913449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:28:03+00:00 2026-06-15T04:28:03+00:00

I have two independent classes that model my tables. First when a new user

  • 0

I have two independent classes that model my tables. First when a new user is created, the user does not have a record in the certificate tables. So in the view for the certificates I have added a button to add certificates details for this new user.
This is my code for the user view: I omitted the paging/search and filter code to make it simple

public ActionResult Index()
var recipients = from s in db.User
                         select s;
 return View(recipients.ToList());

This is the details view showing related data:

   public ViewResult Details(int id)
   {

   var certificateDetails = db.Certificate.Where(p => p.ID == id);
   return View(certificateDetails);
   }

Adding a new user means also adding a new certificates details. I want when a user clicks details for the a particular user if those details aint around to be redirected to a create certificate view with both User.ID and CertificateID set. In fact CertificateID is AI but ID from User is foreign key.
I would have used Fluent API but am not good with it either so have to handle this seemingly small challenge in code.

  • 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-06-15T04:28:04+00:00Added an answer on June 15, 2026 at 4:28 am

    If I understand your question correctly, you want it so that when you view Details(), if the certificate details don’t exist, then redirect to a page to create them?

    Just check whether or not the entity exists. If it doesn’t, return a RedirectToAction() and pass whatever data you need in the route data collection.

    public ViewResult Details(int id)
    {
        var certificateDetails = db.Certificate.FirstOrDefault(p => p.ID == id);
    
        if (certificateDetails == null)
            return RedirectToAction("Create", "Certificate", new { userId = id });
    
        return View(certificateDetails);
    }
    

    You’ll also need to create a Certificate controller with a Create() action.

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

Sidebar

Related Questions

So i have two classes that are independent of eachother, but both are related
I'm going to have two independent programs (using SqlAlchemy / ORM / Declarative) that
I have a project that uses two independent Android libraries. Each of them contains
I have two classes (MVC view model) which inherits from one abstract base class.
Say that I have two classes called Book and Library as follow: var Book
I have two classes, one which is hardware-dependent and one which is not (let's
In Access 2007, I have two tables related such that the (surrogate) PK of
I have a XAML form that I would like two independent features threaded out
Say I have two independent classes: class Foo { int bar; } class Baz
I have two completely independent web application that each use a shared core dll.

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.