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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:04:24+00:00 2026-06-03T04:04:24+00:00

I have a MVC3 action method with 3 parameters like this: var url =

  • 0

I have a MVC3 action method with 3 parameters like this:

 var url = "/Question/Insert?" + "_strTitle='" + title + "'&_strContent='" + content + "'&_listTags='" + listTags.toString() + "'";

and I want to call this by normal javascript function not AJAX (because it’s not necessary to use AJAX function)
I tried to use this function but it didn’t work:

window.location.assign(url);

It didn’t jump to Insert action of QuestionController.

Is there someone would like to help me? Thanks a lot

This is more detail

I want to insert new Question to database, but I must get data from CKeditor, so I have to use this function below to get and validate data

// insert new question
$("#btnDangCauHoi").click(function () {
    //validate input data
    //chủ đề câu hỏi
    var title = $("#txtTitle").val();

    if (title == "") {
        alert("bạn chưa nhập chủ đề câu hỏi");
        return;
    }
    //nội dung câu hỏi
    var content = GetContents();
    content = "xyz";
    if (content == "") {
        alert("bạn chưa nhập nội dung câu hỏi");
        return;
    }
    //danh sách Tag
    var listTags = new Array();
    var Tags = $("#list_tag").children();

    if (Tags.length == 0) {
        alert("bạn chưa chọn tag cho câu hỏi");
        return;
    }

    for (var i = 0; i < Tags.length; i++) {
        var id = Tags[i].id;
        listTags[i] = id;
        //var e = listTags[i];
    }
    var data = {
        "_strTitle": title,
        "_strContent": content,
        "_listTags": listTags.toString()
    };
    //        $.post(url, data, function (result) {
    //            alert(result);
    //        });
    var url = "/Question/Insert?" + "_strTitle='" + title + "'&_strContent='" + content + "'&_listTags='" + listTags.toString() + "'";
    window.location.assign(url); // I try to use this, and window.location also but they're not working
});

This URL call MVC action “Insert” below by POST method

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult Insert(string _strTitle, string _strContent, string _listTags)
    {

        try
        {
            //some code here 
        }
        catch(Exception ex)
        {
            //if some error come up
            ViewBag.Message = ex.Message;
            return View("Error");
        }
        // if insert new question success
        return RedirectToAction("Index","Question");
    }

If insert action success, it will redirect to index page where listing all question include new question is already inserted. If not, it will show error page. So, that’s reason I don’t use AJAX

Is there some one help me? 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-03T04:04:26+00:00Added an answer on June 3, 2026 at 4:04 am

    Try:

    window.location = yourUrl;
    

    Also, try and use Fiddler or some other similar tool to see whether the redirection takes place.

    EDIT:

    You action is expecting an HTTP POST method, but using window.location will cause GET method. That is the reason why your action is never called.

    [HttpPost] 
    [ValidateInput(false)] 
    public ActionResult Insert(string _strTitle, string _strContent, string _listTags)
    {
        // Your code
    }
    

    Either change to HttpGet (which you should not) or use jQuery or other library that support Ajax in order to perform POST. You should not use GET method to update data. It will cause so many security problems for your that you would not know where to start with when tackling the problem.

    Considering that you are already using jQuery, you might as well go all the way and use Ajax. Use $.post() method to perform HTTP POST operation.

    Inside a callback function of the $.post() you can return false at the end in order to prevent redirection to Error or Index views.

    $.post("your_url", function() {
        // Do something
    
        return false; // prevents redirection
    });
    

    That’s about it.

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

Sidebar

Related Questions

I have a function calling a controller method in MVC3. $.getJSON('@Url.Action(LoadCitiesByProvince, Property)', { id:
In my mvc3 POST ActionResult method, I have a portion of code like this:
I have a simple MVC3 Controller Action like this [HttpGet] [OutputCache(Duration = 1200,Location=System.Web.UI.OutputCacheLocation.Server)] public
Its a small question on MVC3 Razor, I have a string ID like a/b
I have built and MVC3 application with a controller (Picture) and an action method
I'm using MVC3 and in my view I have the following code block; Response.Redirect(@Url.Action(index,home,
In an ASP.NET MVC3 application I have an Action method that returns a file
I have MVC3 project & Valums file uploader . The code is following <script
Actually I have some MVC3 Applications and I want to call this applications from
here's my question: I have an MVC3 C# application and I need to update

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.