I'm beginner For the MVC ,Im Developed the My project for Image Upload Script, I want to display my uploaded image in grid, and some one need to replace the Uploaded image to other Image,My code is not working correctly, please help me,
Image
Model
public class MainGroup
{
[DataType(DataType.ImageUrl)]
public string Image { get; set; }
}
View -Index
<table style="border: 1px solid black;" cellpadding="10">
<tr>
<th>
@Html.DisplayNameFor(model => model.Image)
</th>
<th>
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td valign="top">
<img src="@Url.Content("~/Content/Uploaded/" + item.MainGroupID + "/" + item.Image + "")" alt="@item.MainGroupName" width="100px" height="100px" />
</td>
<td valign="top">
@Html.ActionLink("Edit", "Edit", new { id = item.MainGroupID }, new { @class = "createActor", title = "Edit Actor" })
|
@Html.ActionLink("Delete", "Delete", new { id = item.MainGroupID })
</td>
</tr>
}
</table>
Create-Chtml
@using (@Html.BeginForm("Save", "MainGroup"))
{
<div class="editor-field">
<input type="file" name="imageFile" id="imageFile" />
@Html.ValidationMessageFor(model => model.Image)
</div>
<div class="col-md-6" style="font-family:Arial, Helvetica, sans-serif; font-size:13px;"><b>Status</b></div>
<div class="col-md-6">
@Html.CheckBoxFor(a => a.StatusId)
</div>
<div class="col-md-6"></div> <div class="col-md-6"></div>
<div class="col-md-6"></div>
<div class="col-md-6"> <input type="submit" id="btn" value="Save" class="btn btn-success" /> </div>
}
</div>
}
Controller
public class MainGroupController : Controller
{
// GET: Masters/MainGroup
public ActionResult Save(MainGroup maingroup)
{
if (ModelState.IsValid)
{
var objContext = new KnittingdbContext();
maingroup.CreateId = 1;
maingroup.StatusChangeDate = System.DateTime.Now;
maingroup.CreatedDate = System.DateTime.Now;
maingroup.EditId = 1;
maingroup.EditDate = System.DateTime.Now;
objContext.MainGroups.Add(maingroup);
objContext.SaveChanges();
TempData["Success"] = "Saved Sucessfully";
return RedirectToAction("MainGroupIndex", new { A = "New" });
}
else
{
return PartialView("_MainGroupCreate", maingroup);
}
}