I have an ExcelResult action result that returns Microsoft Excel documents, based off the Stephen Walther tip. Basically it just writes a stream out to the Response. When debugging VS 2010 (ASP.NET Dev Server), it runs fine, but when I run it on an IIS 6 box, I get the following error:
The view 'GenerateExcel' or its master was not found. The following locations were searched: ~/Views/Home/GenerateExcel.aspx ~/Views/Home/GenerateExcel.ascx ~/Views/Shared/GenerateExcel.aspx ~/Views/Shared/GenerateExcel.ascx
There is no associated View, and therefore no file, but there shouldn't have to be. What am I doing wrong?
UPDATE
By simply returning void instead of an ActionResult, I no longer have this issue. Instead of returning the ExcelResult, I'm explicitly calling it's ExecuteResult method, which is writing to the output stream.
Before
public ActionResult GenerateExcel()
{
return this.Excel(parameters);
}
After
public void GenerateExcel()
{
ExcelResult excelResult = this.Excel(parameters);
excelResult.ExecuteResult(null);
}
After that, I had security issues with my NTLM authentication, but they 'went away' (meaning I expect them to come back). For now, though, everything is working properly.
Basically @Html. ActionLink() or <a></a> tag uses get request to locate the page. Hence whenever you clicked it, you request to your AddToCart action method in ProductController and if that action method returns null or void so a blank or empty page is shown as you experienced (because or @Html.
All the public methods of the Controller class are called Action methods. They are like any other normal methods with the following restrictions: Action method must be public. It cannot be private or protected.
For MVC action command overrides, extend the BaseMVCActionCommand class, and the only method you'll need to override is doProcessAction , which must return void . It's straightforward to override MVC action commands while keeping your code decoupled from the original action methods.
Make sure your action method does not return a ActionResult:
public void DoSomething()
This is quite useful in a scenario when we have hundreds or thousands of views. Will in that case we create hundreds or thousands of controller actions? Of course not, then how can we fix it?
In the MVC Framework, the controller class includes a method, HandleUnknownAction(), that executes whenever we attempt to invoke an action (or when we request a view that has no matching action method) on a controller that does not exist.
I believe,this answers your question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With