这是我的控制器: -
[HttpPost]
public ActionResult Registor(User_CV cvfiles, User_CVviewModel cvmodel, User_Account useraccount,RegisterModel model)
{
if (ModelState.IsValid)
{
int count = 0;
var file = cvmodel.Cv_Path;
if (file != null && file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Content/CV"), fileName);
file.SaveAs(path);
count++;
db.User_CV.Add(new User_CV
{
Cv_Path = Request.Files[0].FileName
});
db.User_Account.Add(new User_Account {
//Cv_ID = model.Cv_ID,
Full_Name = model.Full_Name,
Email = model.Email,
Contact_No = model.Contact_No,
Password = model.Password,
Fuctional_Area = model.Fuctional_Area
});
db.SaveChanges();
}
return RedirectToAction("Login");
}
else
{
ModelState.AddModelError("","Account creation was unsuccessful. Please correct the errors and try again.");
}
return View(model);
}
这是我的模特: -
public class RegisterModel
{
[Required]
[Display(Name = "Full Name")]
public string Full_Name { get; set; }
[Required]
[Display(Name = "Email")]
[DataType(DataType.EmailAddress)]
[Remote("Registor", "ApplicantAcc", HttpMethod = "POST", ErrorMessage = "Email already exists. Please enter a different Email.")]
public string Email { get; set; }
[Required]
[Display(Name = "Contact No")]
public string Contact_No { get; set; }
[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "Password")]
public string Password { get; set; }
[Required]
[Display(Name = "Functional Area")]
public string Fuctional_Area { get; set; }
public int Cv_ID { get; set; }
public string Cv_Title { get; set; }
public string Cv_Defualt { get; set; }
public string Cv_Path { get; set; }
}
这是我的观点: -
@model _24By7CallAndBPOPvtLtd.Models.RegisterModel
<div class="login-page">
<div class="form">
@using (Html.BeginForm("Registor", "ApplicantAcc", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="alert-danger1" id="abc">
@Html.ValidationSummary(true,"")
</div>
@Html.TextBoxFor(model => model.Full_Name, new { @placeholder = "Full Name" })
@Html.ValidationMessageFor(model => model.Full_Name, "", new { @class = "text-danger" })
...........
@Html.TextBoxFor(model => model.Cv_Path, new { @id = "cvfile", @type = "file", @name = "filename", @value = "Upload", @placeholder = "Full Name" })
@Html.ValidationMessageFor(model => model.Cv_Path, "", new { @class = "text-danger" })
<button type="submit" value="Create">create</button>
<p class="message">Already registered? <a href="Login">Sign In</a></p>
}
</div>
</div>
我想将cv_id发送到用户表,它变为空,请任何人帮助我。我尝试通过隐藏的字段,但我真的不知道隐藏的字段
答案 0 :(得分:0)
添加User_CV后调用SaveChanges。然后将填写身份证。
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
progressDialog.dismiss();
if (success==1){
// start new Activity here
}
else {
// show fail message
}
}
答案 1 :(得分:0)
db.User_Account.Add(new User_Account
{
Full_Name = model.Full_Name,
Email = model.Email,
Contact_No = model.Contact_No,
Password = model.Password,
Deptt_Id =model.Deptt_Id,
});
db.SaveChanges();
User_Account useraccounts= db.User_Account.Where(j => j.Email == model.Email).SingleOrDefault();
db.User_CV.Add(new User_CV
{
Cv_Path = Request.Files[0].FileName,
User_Id = useraccounts.User_Id,
Cv_Title = Path.GetFileName(Request.Files[0].FileName)
});
db.SaveChanges();