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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:25:59+00:00 2026-06-03T08:25:59+00:00

So, I’m working on a new project using ASP.NET MVC. Honestly I don’t have

  • 0

So, I’m working on a new project using ASP.NET MVC. Honestly I don’t have pretty much experience with it (or any web development) before so maybe its a simple question.

I have a partial view that’s a search box that is shared between various of the web views. The view has a drop down list and a text box. I need that once the user post the form (using the search button) that values arrive to the index action of the search controller as a SearchFilterModel object.

Now, the form is calling the index action on the Search controller. That’s working (see attached code). But the thing is, the id param (that must be a SearchFilterModel) of the index method doesn’t arrive (it’s null).

I don’t know how to pass the object from the form to the controller. ¿What I’m doing wrong?

The thing is if I replace new { id = search } with new { id = "something" } (changing the type of the sent parameter, then an string arrives (it works) or if I write new { id = 1 } then an int arrives. I guess there’s something related with the thing that SearchFilterModel isn’t a native type but a complex one.

Any idea?

@using Hermes.Models.Helpers

@{
    var search = CacheHelper.Instance.SearchFilter;
    using (Html.BeginForm("Index", "Search", new { id = search  }, FormMethod.Post))
    {
        @Html.ValidationSummary(true, "No se creó la cuenta. Corrija los errores e inténtelo de nuevo.")
        <div>
            <fieldset>
                <legend>Búsqueda por tipo de producto</legend>

                <div class="editor-label">
                    @Html.LabelFor(s => search.SearchFilter)
                    &nbsp;&nbsp;&nbsp;
                    @Html.DropDownListFor(s => search.SelectedSearchFilter, new SelectList(search.SearchFilter))
                    &nbsp;&nbsp;&nbsp;
                    @Html.LabelFor(s => search.SearchQuery)
                    &nbsp;&nbsp;&nbsp;
                    @Html.TextBoxFor(s => search.SearchQuery)
                    @Html.ValidationMessageFor(s => search.SearchQuery)
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="submit" value="Buscar" />
                </div>
            </fieldset>
        </div>
    }
}

Search Controller’s Index Action

[HttpPost]
        public ActionResult Index(SearchFilterModel id)
        {
            var x = CacheHelper.Instance.SearchFilter;

            ViewBag.Filter = id.SelectedSearchFilter;
            ViewBag.msg = String.Format("Se están buscando {0}, con el filtro {1}", id.SelectedSearchFilter, id.SearchQuery);
            ViewBag.ResultsCount = 0;

            return View();
        }

SearchFilterModel

public class SearchFilterModel
{
    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "¿Qué características?")]
    public string SearchQuery { get; set; }

    [Required]
    [DataType(DataType.Text )]
    [Display(Name = "¿Qué buscar?")]
    public List<String> SearchFilter { get; set; }

    [Required]
    [DataType(DataType.Text)]
    [Display(Name = "¿Qué buscar?")]
    public string SelectedSearchFilter { get; set; }
}
  • 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-03T08:26:01+00:00Added an answer on June 3, 2026 at 8:26 am

    None of the posted answers work so finally the solution was:

    In the “Home” controller (its view renders the “Search” partial view) I declare a new instance of the SearchViewModel, pass it to the “Home” view (via ViewBag) recover it on the “Home” view and the pass it to the “Search” partial view via Render method:

    SearchFilterModel searchFilter = ViewBag.SearchFilter;
    @Html.Partial("SearchProduct", searchFilter)
    

    Now, on the “Search” view, just declare the Begin form as usual and now it works perfectly. It seems (to me) that the problem is related with the lifetime of the object (on my question and my original attempt I was trying to declaring it just before the form and it seems to me that it isn’t possible to do that). Now, it works great but I’m concern about the performance implications on doing it this way. Any suggest’ll be greatly appreciated.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

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.