Imageresizer を使用して写真をアップロードしています。受け取った URL を取得してビューに返したい。必要な URL がありますが、それ以上返すことはできません...これは現時点での私のコードです。
public ActionResult UploadPhoto(Image img, HttpPostedFileBase file, ProfilePageModel model)
{
var currentUser = CommunitySystem.CurrentContext.DefaultSecurity.CurrentUser;
bool isAccepted = false;
string fileName = string.Empty;
if (file.ContentLength > 0)
{
string fName = System.Guid.NewGuid().ToString();
// Generate each version
foreach (string fileKey in System.Web.HttpContext.Current.Request.Files.Keys)
{
HttpPostedFile uploadFile = System.Web.HttpContext.Current.Request.Files[fileKey];
// Generate a filename (GUIDs are best).
fileName = Path.Combine("~/uploads/", fName + format);
// Let the image builder add the correct extension based on the output file type
ImageBuilder.Current.Build(uploadFile, fileName, new ResizeSettings(
"width=300;format=jpg;mode=max;crop=20,20,80,80;cropxunits=100;cropyunits=100"));
model.fileName = fileName;
}
return RedirectToAction("EditProfile");
}
return RedirectToAction("EditProfile");
}
これを実行すると、「ファイルをアップロードして [送信] を押す」と、モデルが null であることがわかります。モデルには、名前、出身国などのプロファイルに関する情報が含まれています。
モデルを返すことができるように、モデルに値を追加する必要があります(クラッシュしないようにします)。何か案は?