Nasim Bahar Nasim Bahar - 1 month ago 18
ASP.NET (C#) Question

How to return different type from Asp.net MVC Controller?

I am posting data to Controller . if data is valid a pdf file is downloading.

if data is not valid I am loading same view again.

Note: I search that during the downloading a file when can't load a view or redirect to another Controller .
below is my Controller Code!!!!

public ActionResult Index(Rentwithholding obj)
{
if (ModelState.IsValid)
{
this.TaxPayerName = obj.TaxPayerName;
this.TINNumber = Convert.ToInt64(obj.TINnumber);
this.TaxPeriodID = obj.TaxPeriodNumber;
findBussnissType(Convert.ToInt64(obj.TINnumber));
getalldates();
if (obj.TenPercentRent != "")
{
this.TenPercentRent = Convert.ToDouble(obj.TenPercentRent);
this.CalculteTenPercentTax();
}
if (obj.FifteenPercentRent != "")
{
this.FifteenPercentRent = Convert.ToDouble(obj.FifteenPercentRent);
this.CalculteFifteenPercentTax();
}
this.PrintPdf();

}
else
{
ViewBag.message = "Incorrect Captcha";
return View("Index", obj);
}
}

Answer

Just return null after PrintPdf();

Comments