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

  • Home
  • SEARCH
  • 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 3843646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:58:04+00:00 2026-05-19T15:58:04+00:00

I Have a Strongly typed user control which i use for Searching a certain

  • 0

I Have a Strongly typed user control which i use for Searching a certain list of objects.
the following code shows the user control,

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<PeercoreCRM.ViewModels.CustomerFilterViewModel>" %>
<div style="width: 100%;vertical-align:top;background-color:White">    
    <fieldset>
        <legend>Criteria</legend>
        <table cellspacing="0">
            <tr>
                <td style="width: 100px">
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.LeadName) %>
                    </div>
                </td>
                <td>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(m => m.LeadName) %>
                    </div>
                </td>
            </tr>

            <tr>
                <td style="width: 60px">
                    <div class="editor-label">
                        <%: Html.LabelFor(m => m.CustomerCode) %>
                    </div>
                </td>
                <td>
                    <div class="editor-field">
                        <%: Html.TextBoxFor(m => m.CustomerCode)%>                         
                    </div>
                </td>
            </tr>                            

            <tr>
                <td>
                    <input type="submit" name="btnSearch" value="Search" />&nbsp;
                    <input type="submit" name="btnCancel" value="Cancel" />
                </td>
                <td>
                </td>
            </tr>
        </table>

    </fieldset>
</div>

In the View, I show this user control conditionally using the following code snippet,

<% using (Html.BeginForm("CustomerList", "Customer", new { isFiltered = Model.FilterViewModel.IsFiltered }, FormMethod.Post))
   {
    %>
<% if (Model.FilterViewModel.IsVisible) Html.RenderPartial("ListFilterUserControl", Model.FilterViewModel); %>
<% } %>

I have put the Form in the rendering page as this control is used in other views and thereby calling other action methods in different controllers.

I have the following method signature in my controller action method,

[HttpPost]
public ActionResult CustomerList(CustomerFilterViewModel filterModel)
{

    bool filtered = filterModel.IsDirty? FilterCustomers(filterModel):false;
    Session["CurrentPageNumber"] = null;

    return RedirectToAction("CustomerList", new { isFiltered = filtered || filterModel.IsFiltered });
}

My problem is, with this implementation, how can i separately identify which button is clicked (“Search” or “Cancel”) and to write the code depending on that.

  • 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-19T15:58:04+00:00Added an answer on May 19, 2026 at 3:58 pm

    To identify the button that has been passed in, you can group your buttons by adding a name attribute to them:

    <input name="button" type="submit" value="Search" />&nbsp;
    <input name="button" type="submit" value="Cancel" />
    

    then, add a variable that is passed into your post method with the same name of the buttons (in this case “button”) like this:

    [HttpPost]
    public ActionResult CustomerList(string button, CustomerFilterViewModel filterModel)
    {
        if(button.Equals("Search")) 
        {
         bool filtered = filterModel.IsDirty? FilterCustomers(filterModel):false;
        Session["CurrentPageNumber"] = null;
    
        return RedirectToAction("CustomerList", new { isFiltered = filtered || filterModel.IsFiltered });
        } else {
           if(button.Equals("Cancel")) {
                //perform cancel
           }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a strongly typed list of custom objects, MyObject , which has a
I have a strongly typed user control (partial) and I'd like to be able
I have a strongly-typed MVC View Control which is responsible for the UI where
I'm wanting to have a strongly typed user control that accepts the class PaginatedList<T>
As the questions says I have always believed that a strongly typed list is
We have our own ORM we use here, and provide strongly typed wrappers for
I have a strongly typed view from which I want to insert some data.
There's no strongly typed View() method to return an ActionResult. So, suppose I have
i wish to create a reusable ASP.NET MVC ViewUserControl which is strongly typed to
I have two views: create and edit. Both share a strongly typed editor template

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.