I have a strongly typed view called News with a calendar control. I have defined the calendar's selectionchanged handler as follows:
<script runat="server">
void OnCalendarSelectionChanged(Object sender, EventArgs e)
{
var ndt = new Nullable<DateTime>(Calendar1.SelectedDate);
Html.RenderAction("ShowNews", new {dateTime = ndt });
}
</script>
In the controller, I have the following method:
public ActionResult ShowNews(Nullable<DateTime> dateTime)
{
I开发者_开发技巧Enumerable<InvestmentNews> todaysNews = new List<InvestmentNews>(); ;
return View("News", todaysNews);
}
When I click on a date in my calendar, the Index() method in my controller is being invoked instead of ShowViews(). Can someone please explain what is happening?
TIA.
It looks to me like you are trying to use a WebForm control within your MVC action. Generally, this doesn't work. What is undoubtedly happening is that it is causing a postback to your main form to handle the WebForm control event. You should really look at using a client-side calendar, such as the jQuery UI datepicker widget and doing an AJAX post on the date selected event on the jQuery UI datepicker, replacing the news view with the returned HTML from your ShowNews action.
It's probably a routing problem. Pull down Phil Haack's routing diagnostic tool and check your routes.
精彩评论