Please help me regarding this problem i enable to solve this and nobody can help me regarding this problem
[HttpPost]
public ActionResult Create(RegisterationVieModel model, HttpPostedFileBase imageUpload)
{
string message = "";
if (imageUpload != null)
{
string pic = System.IO.Path.GetFileName(imageUpload.FileName);
string path = Server.MapPath("~/Images/" + pic);
imageUpload.SaveAs(path);
}
if (ModelState.IsValid)
{
message = _Data.Insert(model, imageUpload);
return Json(new { message=message });
}
else
{
message = _Data.Insert(model, imageUpload);
return new JsonResult { Data = message };
}
}
And View IS:
@model StudentRegisterationForm.ViewModel.RegisterationVieModel
@{
HtmlHelper.ClientValidationEnabled = true;
ViewBag.Title = "Create";
// Layout = "~/Views/Shared/_LayoutPage1.cshtml";
}
@using (Html.BeginForm("Create", "RegisterForm", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
Html.ValidationSummary(false, "Please Resolve The Following Error","Error");
//Html.ValidationSummary(true);
<div>
<table class="table">
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.StudenName)</td>
<td>@Html.TextBoxFor(model=>model.RegisterForm.StudenName)</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.StudenName)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.Age)</td>
<td>@Html.TextBoxFor(model=>model.RegisterForm.Age)</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.Age)</td>
</tr>
<tr>
<td>Male</td>
<td>@Html.RadioButtonFor(model => model.RegisterForm.Gender, "Male")</td>
<td>Female</td> <td>@Html.RadioButtonFor(model => model.RegisterForm.Gender, "Female")</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.Gender)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.Email)</td>
<td>@Html.TextBoxFor(model=>model.RegisterForm.Email)</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.Email)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.Password)</td>
<td>@Html.PasswordFor(model=>model.RegisterForm.Password)</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.Password)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.Address)</td>
<td>@Html.TextAreaFor(model=>model.RegisterForm.Address)</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.Address)</td>
</tr>
<tr>
<td>@Html.DisplayNameFor(model=>model.RegisterForm.Image)</td>
<td><input type="file" id="imageUpload" name="imageUpload" /></td>
</tr>
<tr>
<td>
@Html.DisplayNameFor(model => model.RegisterForm.city.CityName)
</td><td>Countary</td>
<td>@Html.DropDownListFor(model => model.RegisterForm.CountaryID, new SelectList(Model.CountaryList, "CountaryID", "CountaryName"), "--Select--")</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.CountaryID)</td>
<td>State</td><td>@Html.DropDownListFor(model => model.RegisterForm.StateID, new SelectList(Model.StateList, "StateID", "StateName"), "---Select--")</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.StateID)</td>
<td>City</td><td>@Html.DropDownListFor(model => model.RegisterForm.CityID, new SelectList(Model.CityList, "CityID", "CityName"), "---Select")</td>
<td>@Html.ValidationMessageFor(model=>model.RegisterForm.CityID)</td>
</tr>
<tr><td><input type="submit" id="insert" value="Submit" /></td></tr>
</table>
</div>
<div id="Error">
@Html.ValidationSummary(false)
</div>
}
@*Script Portion of Student Registeration Project *@
@section script{
<script src="~/Scripts/jquery-ui.js"></script>
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
@*<script src="~/Scripts/jquery-1.9.1.js"></script>*@
<script src="~/Scripts/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#insert").click(function () {
var dataObject =
{
StudenName: $("#StudentName").val(),//}fetch the values
Age: $("#Age").val(),
Email: $("#Email").val(),
}
$.ajax(
{
type: "POST",
@* url: '@Url.Action("Create", "RegisterForm")',*@
url: '/RegisterForm/Create',
data: dataObject,
ContentType: "application/json",
dataType: "json",
success: function (data) {
if (data == "Save") {
alert("Data Save");
}
if (data == "Exist") {
alert("Data Exist");
}
},
error: function (data) {
if (data.toString() == "Not Save") {
alert("Data Not Save");
}
},
})
})
})
</script>
}