I am creating a feedback form by FormMethod.Post method in mvc. Now, in my form data is saving but after save the data page is refreshed so that user cant know that data is successfully inserted or not. So, for thats why I want to alert the javascript and refresh the current page.
I have done many things but didnt work anything.
So, let I am showing you the last thing I tried that in this code.
Here is my view
<script>
@ViewBag.scripCall
function Callback() {
alert("Callback function is working");
}
</script>
@using (Html.BeginForm("Create", "FeedBack", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<div class="container">
<div class="row">
<div class="col-sm-3">
<img src="~/images/default.png" style="margin:10px" height="200" width="200" id="imagePreview" />
<input type="file" name="ImageUpload" accept="image/jpeg, image/png" id="ImageUpload"
onchange="ShowImagePreview(this, document.getElementById('imagePreview'))" class="control-label" />
</div>
<div class="col-sm-2">
@Html.LabelFor(model => model.FullName, new { @class = "control-label" })
</div>
<div class="col-sm-8">
@Html.TextBoxFor(model => model.FullName, new { @class = "form-control", placeholder = "Enter The Name" })
</div>
<div class="col-sm-9">
<br />
</div>
<div class="col-sm-1">
@Html.LabelFor(model => model.Occupation, new { @class = "control-label" })
</div>
<div class="col-sm-8">
@Html.DropDownList("Occupation", ViewData["occupationList"] as SelectList, new {@class="control-label", style="width:250px;" })
</div>
<div class="col-sm-9">
<br />
</div>
<div class="col-sm-3">
@Html.LabelFor(model => model.UserFeedBack, new { @class = "control-label" })
</div>
<div class="col-sm-8">
@Html.TextBoxFor(model => model.UserFeedBack, new { @class = "form-control", placeholder = "Enter FeedBack", style="height:250px;" })
</div>
<div class="col-sm-3">
<input type="submit" id="btn_save" class="button" value="Save" />
</div>
</div>
<div class="row">
<span class="control-label" style="color:red">Note : Please do not upload DSLR photo. It does not support. Thank You...!!!</span>
</div>
</div>
}
Here is my controller
public ActionResult Create(FeedBackViewModel feedbackViewModel)
{
try
{
HttpPostedFileBase file = Request.Files["ImageUpload"];
if (file != null)
{
string fileName = Path.GetFileNameWithoutExtension(feedbackViewModel.ImageUpload.FileName);
string extension = Path.GetExtension(feedbackViewModel.ImageUpload.FileName);
fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
feedbackViewModel.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/images/"), fileName));
}
ContentRepository service = new ContentRepository();
int i = service.CreateFeedBack(file, feedbackViewModel);
if (i == 1)
{
ViewBag.scripCall = "Callback();";
return View();
}
else
{
return Content("<script language='javascript' type='text/javascript'>alert('Sorry, Something went wrong. Please Try Again...!!!');</script>");
}
}
catch (Exception ex)
{
return View();
}
}
Now, in this code the latest thing I triedto show the alert by @ViewBag.scripCall and also the refresh the current page but it also not working.
Thank You.
What I have tried:
I tried many of thing but didnt work and the latest thing I tried i.e. by
@ViewBag.scripCall
and also didnt work