我正在使用 Imageresizer 并上传照片。我想获取收到的 URL 并将其返回到我的 View 。我有我想要的 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");
}
当我运行此命令“上传文件并按提交”时,我发现该模型为空,该模型包含有关个人资料的信息,例如姓名、您来自哪个国家/地区等。
我需要以某种方式向我的模型添加值,以便我可以返回它(这样它就不会崩溃)。有什么想法吗?
最佳答案
要使模型具有值,其属性需要存在于表单
中。您至少需要为要通过 POST
发回的每个属性添加隐藏字段。
关于c# - 返回模型但它为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19931455/