I created an ASP.NET MVC 2.0 application.
I have a dropdownbox with a list of "reports". Next to the dropdown, I have two ActionLinks. One that says βAdd a new report,β and the other says βEdit a report."
The "Add a new report" link is pretty simple ... it calls ViewResult in my controller and returns new View()
. Large! It's not a problem!
The Edit Report link is a little more complicated, because I want to pass the selected identifier of the item selected in the drop-down list to ActionLink.
I found an article that shows me how to AJAXify my ActionLink, but Im doing something wrong ...
Here is the ActionLink link in the view for the Edit link:
<%=Html.ActionLink("Edit report", "EditReport", "Report", null, new { id = "edit" })%>
Here is the jQuery click event for handling "click"
$("#edit").click(function() { $.ajax({ url: '<%=Url.Action("EditReport")%>', type: 'POST', data: { reportId: $('select[name="ReportId"] option:selected').val() }, success: function(result) {
Here is the method in the controller:
public ViewResult EditReport(int reportId) { return View("EditReport"); }
When you place a breakpoint in the Controllers method, it gets in and the "reportId" parameter is passed correctly ... but the rest of the code (return View ()) does not work, because inside the jQuery click event, I have "return false".
When you delete "return false" inside the click event, the breakpoint no longer hits. Thus, I cannot go to my view of "EditReport" ...
What am I missing / do not understand here?
Also ... is there a better / nicer / cleaner approach to accomplishing my task without using an AJAX call?