不确定这是否是 MVC 中的最佳方法,但我如何在有条件的情况下返回视图,假设如果我的“fbUID”丢失,我是否想返回另一个显示一些错误消息的视图,请提供帮助。谢谢。
public PartialViewResult GetCredentials(string facebookUID, string facebookAccessTok)
{
string fbUID = facebookUID;
if (fbUID != null)
{
// Request fb profile pic
var rawImg = new Bitmap(ImageHelper.requestBitmapImage(fbUID));
var processblurredImg = new Bitmap(rawImg);
var gb = new GaussianBlur();
for (int i = 0; i < 8; i++)
{
gb.ApplyInPlace(processblurredImg);
}
// Download it to local drive / server
string uploadPath = Server.MapPath("~/upload");
string fullPath = uploadPath + "\\ProfilePic.png";
if (!Directory.Exists(uploadPath))
{
Directory.CreateDirectory(uploadPath);
}
if (uploadPath != null)
{
ImageHelper.savePng(fullPath, processblurredImg, 500L);
}
return PartialView("BlurredPhoto");
}
return PartialView("TestPartialView"); //if fbUID is null
}