2

Have Controller:

public class MyController : Controller
{
    [HttpGet]
    public ActionResult MyAction(int iMode, string strSearch)
    {
        return View();
    }
}

In my view I have a div with id=center

I execute the following code in javascript

url = "/MyController/MyAction?iMode=7&strSearch=as";
$('#center').load(url); 

When debugger his the breakpoint in my action on first line, iMode variable shows proper value of 7, strSearch parameter arrives as null.

Any help/advice would be most welcome.

2 Answers 2

5

Just use the ampersand instead of &

url = "/MyController/MyAction?iMode=7&strSearch=as";

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. Working well now. This string was generated via MVC helper function @Url.Action("MyAction", "MyController", new { iMode ="PLACEHOLDER", strSearch = "PLACEHOLDER1" }) I then did replacements of the placeholders, but assumed the & to be an MVC quirk.
Haha yeah, there's quite a bit of quirks.. You should use the data object in jQuery ajax for sending data. It takes care of the name value pairs, encoding, etc.
0

Thanks Innatepirate for the tip. Wasted enough time trying to figure out why controller is getting null values. Replacing & with ampersand did the trick. By the way I was doing the simple age old window.location.href = link and still had the problem. Probably its the MVC parsing and routing that is messing this up.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.