PDA

View Full Version : [CLOSED] File download In MVC



matrixwebtech
Nov 12, 2014, 7:08 PM
Hi
I am trying to add file download functionality in my application,for that I do bellow code.Its check in Index() function there are download link available or not?If yes then its visible.


X.LinkButton().Text("Download").ID("UploadPath_1")


public ActionResult Index()
{
if (string.IsNullOrWhiteSpace("Some Path") == true)//Check data base field contains path or not.
{
X.GetCmp<LinkButton>("UploadPath_1").Hide();

}
else
{
//string url = "downloadFile?path=VendorQuotation_Document_1_Uploa dPath &" + obj_tbl_Pur_Trans_Quotation_Master.QuotationID + "";
X.GetCmp<LinkButton>("UploadPath_1").Show();
X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.Action = "downloadFile";
X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.FormID = "f";
X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.IsUpload = true;
X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.ExtraParams.Add(new Parameter { Name = "path", Value = "VendorQuotation_Document_1_UploadPath" });
X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.ExtraParams.Add(new Parameter { Name = "id", Value = obj_tbl_Pur_Trans_Quotation_Master.QuotationID.ToS tring(), Mode = ParameterMode.Raw });
}
return View();
}

public void downloadFile(string path, string id)
{

}


after page load downloadFile function not called.

Daniil
Nov 13, 2014, 12:31 PM
Hi @matrixwebtech,

Changing a control's DirectEvents on the fly doesn't affect on client. A DirectEvents option is not supposed to be changed on the fly.

Maybe, you can define a static DirectEvent?

matrixwebtech
Nov 13, 2014, 1:33 PM
hi
daniil,
the problem is the file id is dynamic


X.GetCmp<LinkButton>("UploadPath_1").DirectEvents.Click.ExtraParams.Add(new Parameter { Name = "id", Value = obj_tbl_Pur_Trans_Quotation_Master.QuotationID.ToS tring(), Mode = ParameterMode.Raw });
so is there any way to do this?

Vladimir
Nov 13, 2014, 2:22 PM
Hi

X.GetCmp can be used in conjunction with DirectResult only (it cannot be used with ViewResult) because it generates script for already rendered widgets
If you want to configure some widgets before render in a view then pass required data to the view and set required properties inside view