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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:16:02+00:00 2026-06-13T16:16:02+00:00

big problem here! I know the title is kinda fuzzy, but it’s all day

  • 0

big problem here! I know the title is kinda fuzzy, but it’s all day long I’ve got this problem and cannot figure out how to solve it.
I’ll try to be the more specific in the less messy way.
Long story short, I have a Controller (LeadController) with a method (Search) for a search:

 public ActionResult Search(string prov = null, string city = null)
    {
        //if no field is compiled, return an empty view
        if (String.IsNullOrWhiteSpace(prov) && String.IsNullOrWhiteSpace(city))
            return View();

        var leads = from l in db.Leads
                    select l;

        if (!String.IsNullOrWhiteSpace(prov))
        {
            leads = leads.Where(l => l.Prov == prov).OrderBy(l => l.RagioneSoc);
        }

        if (!String.IsNullOrWhiteSpace(city))
        {
            leads = leads.Where(l => l.Comune == city).OrderBy(l => l.RagioneSoc);
        }

        return View(leads);
    }

Then I have the Search View (displaying the fields to fill for the search AND the result after the post action) with 2 submit forms: the first one to execute the search

@using (Html.BeginForm()){
Sigla Provincia: @Html.TextBox("prov", null, new { @style = "width: 50px;"})
Città: @Html.TextBox("city", null, new { @style = "width: 150px;" })
<input type="submit" value="Ricerca" data-icon="search" data-role="button" data-mini="true" data-inline="true" />}

and the 2nd one to generate a document from the leads result of the search action

<input type="submit" title="create doc" value="Create document" onclick="javascript:postData()" id="doc" />

This last submit should call a javascript function to encode the model:

<script type="text/javascript">
function postData() {
    var urlact = '@Url.Action("createDoc")';
    var model = '@Html.Raw(Json.Encode(Model))';

    $.ajax({
        ...
        ...
    });
}
</script>

Now, the problem is: when I call the first submit, the one which should execute the research, it performs the research but it also keeps going on, calling the postData() javascript function (even if I never “tell” him to do that). And the site stop working in var model = @Html.Raw(Json.Encode(Model))’;, with an InvalidOperationException.

If someone understood my question, is there a way to avoid this behaviour and to force the 1st submit only to pass the controller the parameters to execute the search action?

Hope someone can help me,
thank you in advance for your consideration!


SOLVED

Well, the problem is gone. Apparently, I didn’t know so well the View & Javascript behaviour. Long story shirt, it seems the View, loading itself, enters the js function in order to kind of cache the Model encoding, but it doesn’t fully runs the function! And I had a problem within the interested Model.
I don’t know if I explained myself, but the warning is: be careful for your Model consistency before doing anything else.
Thanks to anyone who helped me, before I realized I get it totally wrong!

  • 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-13T16:16:04+00:00Added an answer on June 13, 2026 at 4:16 pm

    Here is how you should handle multiple submit buttons

    Below is a form with two submit buttons. Note that both these submit buttons have the same name i.e “submitButton”

    @Html.BeginForm("MyAction", "MyController"); %>
    <input type="submit" name="submitButton" value="Button1" />
    <input type="submit" name="submitButton" value="Button2" />
    }
    

    Now over to the Controller, the Action takes in an input parameter called string stringButton and the rest is pretty self-explanatory.

    public ActionResult MyAction(string submitButton) {
            switch(submitButton) {
                case "Button1":
                   // do something here
                case "Button2":
                   // do some other thing here
                default:
                    // add some other behaviour here
            }
    ...
    }
    

    Hope this helps you !

    UPDATE :

    from your comments,

    Hi, I do know this workaround, my issue is the 2nd submit doesn’t have to pass through the Controller: it has to call the javascript function in the View. The 1st post to a Controller in the right way, but THEN it runs the javascript function, too.

    Ok, instead of having two submit buttons, you can have one submit button and other as a normal button.
    Eg: –

    @Html.BeginForm("MyAction", "MyController"); %>
    <input type="submit" name="submitButton" value="Button1" />
    <input type="button" id="otherButton" value="Button2" />
    }
    

    and then using some simple jquery, you can make a call to the javascript funcion postData().

    <script type="text/javascript">
        $("#otherButton").bind("click", function () {
            console.log("do your stuff here");
            postData();
    
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got a big problem here which killed my whole day... I cant fix it
Here is a (big) example of the massive problem I am having, when this
here i am again :( got big problem hiks ... need HELP !!! i
I have a big problem with my server mysql. All worked fine but since
I think this is simple, but I am having big problem with this. I
I'm having a stupid problem here. It's not such a big deal, but as
i know, the title is a bit crampy, but it's a weird problem. i'm
I have a big problem with my app as it crashes often but never
we're having this big problem with our application. It's a rather large application with
I know stretchable...ist the old one (and deprecated)..and resizable..is new - but ONE BIG

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.