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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:09:01+00:00 2026-05-29T10:09:01+00:00

Lets say I have a controller which provides search functions for a student: public

  • 0

Lets say I have a controller which provides search functions for a student:

public class StudentSearchController
{
    [HttpGet]
    public ActionResult Search(StudentSearchResultModel model)
    {
        return View(model);
    }
}

So long as the Search action is provided a StudentSearchResultModel, it will render a list of search results.

Is there a way to effectively extend this action method from another controller? For example, lets say I want to have other controllers that need to search for students, like this:

public class UniStudentController
{
    [HttpPost]
    public ActionResult Search(UniStudentSearchResultModel model)
    {
        return RedirectToAction("Search", "StudentSearch", model);
    }
}

public class HighSchoolStudentController
{
    [HttpPost]
    public ActionResult Search(HighSchoolSearchResultModel model)
    {
        return RedirectToAction("Search", "StudentSearch", model);
    }
}

(presuming both models extend StudentSearchResultModel.)

I obviously can’t do this, because I can’t pass the pre-instantiated model classes to the search controller (the original search controller will recreate a StudentSearchResultModel, rather than using the model that was passed).

The best solution I’ve come up with so far is to move SearchView.cshtml into the “Shared” folder, then I can just render the view from the Uni/HighSchool controllers directly (instead of calling “RedirectToAction”). That works just fine, and in theory I wouldn’t need the StudentSearchController at all. However, I’m building on legacy code here (in this contrived example, StudentSearchController is legacy), so without doing a boatload of refactoring, the “Shared” folder isn’t an option for me.

Another solution would be to put all search related actions into the StudentSearchController – so it would get two actions for UniStudentSearch and HighSchoolStudentSearch. I don’t like this approach though, as it means that the StudentSearchController needs to know about all of its intended usages.

Any ideas?

PS: Not opposed to the refactoring, but am limited by deadlines!

  • 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-29T10:09:02+00:00Added an answer on May 29, 2026 at 10:09 am

    you can put the path of the view in your call to View()

    return View("~/Views/StudentSearch/SearchView.cshtml", model);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a controller class A which implements UIImagePickerControllerDelegate. within A ,
Lets say i have the following controller: // // GET: /Courses/Edit/5 public ActionResult Edit(int
Lets say have this immutable record type: public class Record { public Record(int x,
Lets say I have a class called PageBuilder which I instantiate, send parameters to
Lets say I have a view, myView, a view controller, myViewController, and some sort
Using Rails v2.1, lets say you have an action for a controller that is
Lets say I have the following code: abstract class Animal case class Dog(name:String) extends
Lets say I have a single object of type Car which I want to
Lets say we have something like: <div class=row> <div class=box> <a class=more href=#more/> </div>
Lets say I have a hash which may contain hashes. params: { :action =>

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.