I have created the form and insert it data into data base. Now I want to show Single user details in same view bottom of my form. When I click on submit button record inserted into database and show in table bottom of my form. So how can I do this?
Here is my view code:
@model Edu_Form.Models.VMHiring_edu_Info
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Raw(ViewBag.Message);
@using (Html.BeginForm("Index", "Hiring",FormMethod.Post,new {enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Hiring Eduction information form</h4>
<hr />
<div class="row">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Year_Passing, htmlAttributes: new { @class = "control-label " })
<div class="">
@Html.EditorFor(model => model.Year_Passing, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Year_Passing, "", new { @class = "text-danger" })
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div>
</div>
}
So How can I Show the single user data in table. And which action method I write the code?? I have use code first approach and Linq.
This is HttpPost Action Method:
[HttpPost]
public ActionResult Index(VMHiring_edu_Info Tb_Edu)
{
String Name = Path.GetFileNameWithoutExtension(Tb_Edu.Attachment.FileName);
String Extension = Path.GetExtension(Tb_Edu.Attachment.FileName);
String FullName = Name + Extension;
String FileName = Path.Combine(Server.MapPath("~/Images/"), FullName);
HttpPostedFileBase File = Tb_Edu.Attachment;
int Length = File.ContentLength;
if (Extension.ToLower() == "jpg" || Extension.ToLower() == "jpeg" || Extension.ToLower() == "png" || Extension.ToLower() == "pdf") {
if (Length <= 400000)
{
Hiring_Edu_Info db_Edu = new Hiring_Edu_Info
{
Level = Tb_Edu.Level,
Board_Uni_Ins = Tb_Edu.Board_Uni_Ins,
City = Tb_Edu.City,
Country = Tb_Edu.Country,
Year_Passing = Tb_Edu.Year_Passing,
Division = Tb_Edu.Division,
Grade = Tb_Edu.Grade,
CGPA = Tb_Edu.CGPA,
Percentage = Tb_Edu.Percentage,
M_Obtained = Tb_Edu.M_Obtained,
M_Total = Tb_Edu.M_Total,
Attachment = FileName,
IsDegreeCompleted = Tb_Edu.IsDegreeCompleted == "1" ? true : false,
UserId = Tb_Edu.UserId,
Degree_Title = Tb_Edu.Degree_Title
};
db.Hiring_Edu_Info.Add(db_Edu);
int a = db.SaveChanges();
if (a > 0)
{
ViewBag.Message = "<sript>alert('Record inserted')</sript>";
ModelState.Clear();
}
}
}
else
{
ViewBag.Message = "<sript>alert('Record not inserted')</sript>";
}
}
This is my model class:
public class VMHiring_edu_Info
{
[Required]
public String Level { get; set; }
[Required]
public string Degree_Title { get; set; }
[Required]
public String Board_Uni_Ins { get; set; }
[Required]
public String City { get; set; }
[Required]
public String Country { get; set; }
[Required]
public String IsDegreeCompleted { get; set; }
[Required]
public String SUBJECTS_MAJORS { get; set; }
[Required]
public String Division { get; set; }
[Required]
public String Grade { get; set; }
[Required]
public String Percentage { get; set; }
[Required]
public String CGPA { get; set; }
[Required]
public String M_Obtained { get; set; }
[Required]
public HttpPostedFileBase Attachment { get; set; }
[Required]
public String M_Total { get; set; }
public String UserId { get; set; }
public String Year_Passing { get; set; }
}
