editorforModel但现在我需要几个不同的,我不想使用html助手onebyone。所以我需要这样的东西;
@model JobTrackingSystem.Areas.Panel.ViewModels.Member.NewMemberModel
{
@Html.EditorForModel()
}
@model JobTrackingSystem.Areas.Panel.ViewModels.Member.MemberDashboardModel
{
@Html.EditorForModel()
}
所以我想将它们保存在1页的2个不同的div中,但我的控制器也不允许使用这样的东西 这是我的控制器;
public ActionResult Add(NewMemberModel input, HttpPostedFileBase Resim)
{
if (!ModelState.IsValid)
{
ShowErrorMessage("Hatalı İşlem Yaptınız.");
return RedirectToAction("Index");
}
if (Resim == null)
{
ShowErrorMessage("Lütfen Boş Alan Bırakmayın.");
return RedirectToAction("Index");
}
var epostaKontrol = Db.MyMembers.FirstOrDefault(p => p.Mail == input.Mail);
if (epostaKontrol != null)
{
ShowErrorMessage("E-Mail Adresi Adı Kullanımda.");
return RedirectToAction("Index");
}
string[] folders = new string[] { "Uploads/Member/Orjinal/", "Uploads/Member/Kucuk/" };
string fileExt = Path.GetExtension(Path.GetFileName(Resim.FileName)).ToLower();
string orjName = Guid.NewGuid() + fileExt;
string filePath = Path.Combine(Server.MapPath("~/" + folders[0]), orjName);
string fileThumbPath = Path.Combine(Server.MapPath("~/" + folders[1]), orjName);
if (!(fileExt.Equals(".jpg") || fileExt.Equals(".jpeg") || fileExt.Equals(".png")))
{
ShowErrorMessage("Yalnızca .Jpg .Jpeg ve .Png Uzantılı Dosyalar Yükleyebilirsiniz.");
return RedirectToAction("Index");
}
Resim.SaveAs(filePath);
var thumber = ImageHelper.Thumber(750, filePath, fileThumbPath);
if (!String.IsNullOrWhiteSpace(thumber))
{
ShowErrorMessage(thumber);
return RedirectToAction("Index");
}
var item = new Member
{
Name = input.Name,
Mail = input.Mail,
SurName = input.SurName,
Phone = input.Phone,
Sira = Db.MyMembers.Max(m => (short?)m.Sira) ?? 0 + 1,
DepartmentType = (DepartmentTypeForUser)input.DepartmentTypeFor,
MemberType = (MemberTypeForUser)input.MemberTypeFor,
Image = "/" + folders[1] + orjName
};
item.SetPassword(input.Password);
Db.MyMembers.Add(item);
Db.SaveChanges();
ImageResizeModel model = new ImageResizeModel()
{
ImagePath = "/" + folders[1] + orjName,
ImageThumbPath = "/" + folders[1] + orjName,
SelectionSize = "[ 750, 750 ]",
};
return View("CropImage", model);
}
那么如何在不同的模型字段中多次使用多个editorforModel
?我可以在NewMemberModel
类中执行类似2方法的操作,然后调用editorforModelMethod1 - editorforModelMethod2
吗?
答案 0 :(得分:1)
我并不完全清楚你要问的是什么(尤其是#34;控制器不会允许",实际的错误信息会对我们有帮助,可以帮助你研究问题),但看起来你可以使用复合视图模型:
public class NewMemberWithDashboardModel
{
public NewMemberModel NewMember { get; set; }
public MemberDashboardModel MemberDashboard { get; set; }
}
然后像这样使用它:
@Html.EditorFor(m => m.NewMember)
@Html.EditorFor(m => m.MemberDashboard)
在你的控制器中:
public ActionResult Add(NewMemberWithDashboardModel model, ...)