I'm stuck with the following scenario:
On my view there's a list of items. Depending on what the item represents, clicking on an item will take you to the appropriate view and display those results. Now displaying results in a view is not a problem; that is working fine. However, some items should be displayed in a popup and not in a view. I'm using a partial view together with bPopup and a javascript function like ShowListDialog(data) to show the dialog and bind the data. How do I call the javascript function upon returning whatever result needs be (I'm suspecting JavaScriptResult) in the action.
What I think my action should look like at the moment is:
public ActionResult ResponseItem(int reference) { ResponseBase response = repository.RetrieveResponse(reference);
if (response.ShouldShowInView)
{
return View(response.RedirectUrl, response.Data);
}
else
{
return JavaScript("ShowListDialog(" + response.Data.JsonString + ");");
}
}
I have been looking at examples of return a JavaScript result and I can't even get that to work. If I say something like:
return JavaScript("alert('Hello');");
then in IE it asks me if I would like to open the javascript file; and in Chrome and Firefox it simply displays alert('Hello'); on the page.
Thanks in ad开发者_如何学Cvance for help :) D
when looping through the items can you decide which is pop up and which isn't then link to 2 separate actions based on that?
JavaScriptResult only works if you call the action through ajax so that might be why it's not working (in case you aren't). you could prob use this to tell in action if it's an ajax request then return the appropriate result.
精彩评论