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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:41:48+00:00 2026-06-11T12:41:48+00:00

Hi all Currently I have a website that has a button and some javascript

  • 0

Hi all Currently I have a website that has a button and some javascript that creates a loading look and then runs this actionresult. I want to add parameters to actionresult but not sure how to do it. Thanks! Here is my code
Controller:

    [HttpPost]
    public ActionResult PostMethod(string MyText)
    {
        System.Threading.Thread.Sleep(5000);

        return Json("And were done");
    }

View:

<input type="text"  name="MyTextBlock"/>
<p id="PID">
Default message from declarative syntax.
</p>
<div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001;
opacity: .8; filter: alpha(opacity=70);display:none" >
<p style="position: absolute; top: 30%; left: 45%; color: White;" align="center">
    <img src="../../Content/themes/base/images/ajax-loading.gif"><br />
    Loading, please wait...
</p>
</div>

<button onclick="JavascriptFunction();">HTTPPost Button</button>

<script type="text/javascript" language="javascript">
function JavascriptFunction() {
    var url = '@Url.Action("PostMethod", "MyTextBlock", new { MyText = "john" })';
    $("#divLoading").show();
    $.post(url, null,
            function (data) {
                $("#PID")[0].innerHTML = data;
                $("#divLoading").hide();
            });
}
</script>

What I want to do is pass MyTextBox into PostMethod to use it as MyText. Some of the other examples I have seen hardcode in values where I want it to be from the textbox. Any help is greatly appreciated. Thanks!

  • 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-11T12:41:49+00:00Added an answer on June 11, 2026 at 12:41 pm

    It seems like you’re trying to hand code a lot of what MVC already handles for you. Try this out…

    First out, create a model for your view. You can call this whatever you want. Put the properties that you want as your parameters to your action method in here.

    YourModel.cs

    public class YourModel
    {
        public string MyText { get;set; }
    }
    

    For your controller, you’ll have to change two things. The GET action for the page will need a model passed to it, like shown below.

    For the POST action, change your string MyText parameter to YourModel model. This will allow MVC to bind your inputs on your view to the model.

    Action Method

    public class YourController
    {
        [HttpGet]
        public ActionResult PostMethod()
        {
            YourModel model = new YourModel();
            return View(model);
        }
    
        [HttpPost]
        public ActionResult PostMethod(YourModel model)
        {
            //Do something with model.MyText;
            System.Threading.Thread.Sleep(5000);
            return Json("And We're Done");
        }
    }
    

    PostMethod.cshtml

    //THIS LINE HERE IS THE MOST IMPORTANT
    @model YourNamespace.YourModel
    //Ajax will handle most of the calling and showing of your elements if you tell it what to do!
    @using(Ajax.BeginForm(new AjaxOptions(){ LoadingElementId="divloading", OnSuccess="OnSuccessFunction" }))
    {
        <input type="text"  name="MyText"/>
        //Quick note: If you decide to hand code your html, make sure your <input/> name attributes match the property names on your model object.
        //Or here you could do @Html.TextBoxFor(m => m.MyText)
        <p id="PID">
        Default message from declarative syntax.
        </p>
        <div id="divLoading" style="margin: 0px; padding: 0px; position: fixed; right: 0px;
        top: 0px; width: 100%; height: 100%; background-color: #666666; z-index: 30001;
        opacity: .8; filter: alpha(opacity=70);display:none" >
        <p style="position: absolute; top: 30%; left: 45%; color: White;" align="center">
            <img src="../../Content/themes/base/images/ajax-loading.gif"><br />
            Loading, please wait...
        </p>
        </div>
    
        <input type="submit" name="Submit" value="HTTPPost Button"/>
    
        <script type="text/javascript" language="javascript">
        function OnSuccessFunction(data, textStatus, jqXHR){
             $("#PID")[0].innerHtml = data;
         }
        </script>
    }
    

    Some benefits of doing it this way is now your JS doesn’t have to change if you add more properties to your model. You just add another input to your view using either the HtmlHelper or hand code the input name with the name attribute equal to the name of the property on your model. MVC will handle the rest.

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

Sidebar

Related Questions

currently I have an app that creates all sorts of different requests to Facebook
I currently have the following SQL query that lists all the names of all
We currently have an error catching script for all our PHP sites. This script
Hello I currently have this code checking if a cookie exists, it works all
Currently I have a UITabBarController with 4 items on it that all have associated
Currently I have a url like this http://<client_name>.website.com/index.php?function_name&cat=32 I want to set things up
I have a website project. It has assembly references to external DLLs that we
I'm working on a website that has a header that stretches all the way
I'm currently working on a website that works without any javascript. I'm going to
I have a website that has a secure area (https) and the rest of

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.