I want to auto generate the ID which incremented from my previous ID. ID format is A00001, A00002,... .. I dunno how to auto generate
Controller
[HttpPost]
public ActionResult Create(Assignment assignment)
{
if (ModelState.IsValid)
{
if (Request.Files.Count > 0)
{
HttpPostedFileBase assignmentFile = Request.Files[0];
if (assignmentFile.ContentLength > 0)
{
var fileName = Path.GetFileName(assignmentFile.FileName);
assignment.FileLocation = Path.Combine(Server.MapPath("~/Content/File"), fileName);
assignmentFile.SaveAs(assignment.FileLocation);
}
}
db.Assignments.Add(assignment);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(assignment);
}
Model
public partial class Assignment
{
public Assignment()
{
this.CourseAvailables = new HashSet<CourseAvailable>();
}
public string AssignmentID { get; set; }
public Nullable<System.DateTime> SubmissionDate { get; set; }
public string Status { get; set; }
public Nullable<decimal> Mark { get; set; }
public string Comments { get; set; }
public string FileLocation { get; set; }
public virtual ICollection<CourseAvailable> CourseAvailables { get; set; }
}
View
<% using (Html.BeginForm("Create", "Assignment", FormMethod.Post, new { enctype = "multipart/form-data" }))
{ %>
<%: Html.ValidationSummary(true) %>
<fieldset>
<legend>Assignment</legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.SubmissionDate) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.SubmissionDate) %>
<%: Html.ValidationMessageFor(model => model.SubmissionDate) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Status) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Status) %>
<%: Html.ValidationMessageFor(model => model.Status) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Mark) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Mark) %>
<%: Html.ValidationMessageFor(model => model.Mark) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Comments) %>
</div>
<div class="editor-field">
<%: Html.EditorFor(model => model.Comments) %>
<%: Html.ValidationMessageFor(model => model.Comments) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.FileLocation) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.FileLocation, new { type="file"})%>
<%: Html.ValidationMessageFor(model => model.FileLocation) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
I want to auto generate the ID which incremented from my previous ID. ID format is A00001, A00002,... .. I dunno how to auto generate