1

I am working on a simple CMS project, and i have run into a wall. And then after a lot of hours, blew it up.

For some reason my buttons inside @Ajax.BeginForm were not activating the postback. Neither full postback nor ajax. I have referenced the scripts, and tried to debug jQery, examined every character in the Controllers, Views, References and Models to no avail. There were no errors or exceptions thrown.

Controller action:

[HttpPost]
public ActionResult Delete(int ID,int page=1)
{
  //some code...
  //...work, work, work...
}

View segment:

@using (Ajax.BeginForm("Delete", "Client", new { page = Model.CurrentPageIndex }, ao))
{
    @Html.Hidden("clientID", item.ClientID)
    <input type="submit" value="Briši" name="brisi" />
}

Error:

The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Delete(Int32, Int32)' in 'Info3CRM.WebUI.Controllers.ClientController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

Finally i have decided to disable jQuery and Ajax and do normal postback. Then the exception was thrown. I was trying to call the Action in controller without all the necessary parameters.

My question to all is: How to catch such an exception if jQuery and ajax are enabled?

2 Answers 2

1

You could see this error in some kind of client side debugging tool.

For example, Fiddler would show you the response that came back from the server - and you can use Fiddler's WebView tab to see the HTML response. The HTML response in this case would show you the ASP.NET yellow error screen.

In addition to Fiddler, you could also use browser debugging tools that come built into IE,, Chrome or Opera - or download Firebug for FireFox. Each tool has a network tab which will show you all the ajax requests and their responses.

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

2 Comments

Thank You!!! Believe it or not, i have been using firebug for years but mostly just to fix CSS, and try and debug JS, i have not gone all the way to the Net tab.....
Not a problem - glad I could help. ;)
0

Your problem is that the action you are POSTing to expects to find a parameter named ID, while there is no such parameter being POSTed. If you change the name of the hidden input to match the name of the parameter it should all work fine.

So, change

@Html.Hidden("clientID", item.ClientID)

to

@Html.Hidden("ID", item.ClientID)

1 Comment

I do know that now, but my problem was figuring this out. Since no exception was throw, i couldn't find the problem. Here it is obvious, in the original problem, the typo was i vs ì

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.