TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Tabor
586
2k
464.4k
how to load data as listing after saving it into the db mvc
Oct 14 2019 12:05 AM
I have a profile page in which i have an education section for that i have created a partial view and on button click i am opening the partial view and then saving the data but after saving it is not loading the grid with latest data i need to refresh the page . check the below code
[HttpPost]
[ValidateAntiForgeryToken]
public
ActionResult Create([Bind(Include =
"ID,Degree_Level,Degree_Name,Institution_Attended,User_Id,BoardORUniversity,MarksObtained,TotalMarks,Year_Passed,Active,Date_Started,Date_End,Date_Created,Date_Modified"
)] Student_Experience student_Experience)
{
ViewBag.Colleges = _IEducation.PopulateColleges();
if
(ModelState.IsValid)
{
db.Student_Experience.Add(student_Experience);
db.SaveChanges();
return
RedirectToAction(
"Index"
);
}
return
View(student_Experience);
}
My Partial view is below
@model CMS_Monitoring.Models.Student_Experience
@{
/**/
Layout =
null
;
}
<!DOCTYPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>Create</title>
<script>
$(document).ready(function () {
// $(document.getElementById("sbmtInput").click(function(e){}
$(
'input[type=submit]'
).click(function (e) {
e.preventDefault();
$.ajax({
type:
"POST"
,
url:
'@Url.Action("Create", "Student_Experience")'
,
// dataType: "json",
data: $(
'form'
).serialize(),
success: function (result) {
// document.getElementById("demo1").innerHTML = "";
$(
".demo1"
).html(result);
},
error: function () {
}
});
});
});
</script>
</head>
<body>
@
using
(Html.BeginForm())
{
<div
class
=
"form-horizontal"
>
@*<h4>Add Qualification</h4>
<hr />*@
@Html.ValidationSummary(
true
,
""
,
new
{ @
class
=
"text-danger"
})
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Degree_Level, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.DropDownListFor(model=>model.Degree_Level,
new
List<SelectListItem>
{
new
SelectListItem{ Text=
"Select Degree"
, Value =
"0"
},
new
SelectListItem{ Text=
"High School"
, Value =
"1"
},
new
SelectListItem{ Text=
"Intermediate"
, Value =
"2"
},
new
SelectListItem{ Text=
"Bechelor's"
, Value =
"3"
},
new
SelectListItem{ Text=
"Master's"
, Value =
"4"
},
new
SelectListItem{ Text=
"Doctorate (PhD)"
, Value =
"5"
},
new
SelectListItem{ Text=
"Vocational"
, Value =
"6"
},
new
SelectListItem{ Text=
"Associate Degree"
, Value =
"7"
},
new
SelectListItem{ Text=
"Certification"
, Value =
"8"
},
},
new
{ @
class
=
"btn form-text"
, @id =
"myid"
})
@Html.ValidationMessageFor(model => model.Degree_Level,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Degree_Name, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Degree_Name,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Degree_Name,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Institution_Attended, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Institution_Attended,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Institution_Attended,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
@*<div
class
=
"form-group"
>
@Html.LabelFor(model => model.User_Id, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.User_Id,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.User_Id,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>*@
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.BoardORUniversity, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.BoardORUniversity,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.BoardORUniversity,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.MarksObtained, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.MarksObtained,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.MarksObtained,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.TotalMarks, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.TotalMarks,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.TotalMarks,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Year_Passed, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Year_Passed,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Year_Passed,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Active, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
<div
class
=
"checkbox"
>
@Html.EditorFor(model => model.Active)
@Html.ValidationMessageFor(model => model.Active,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Date_Started, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Date_Started,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Date_Started,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Date_End, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Date_End,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Date_End,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
@*<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Date_Created, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Date_Created,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Date_Created,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>
<div
class
=
"form-group"
>
@Html.LabelFor(model => model.Date_Modified, htmlAttributes:
new
{ @
class
=
"control-label col-md-2"
})
<div
class
=
"col-md-10"
>
@Html.EditorFor(model => model.Date_Modified,
new
{ htmlAttributes =
new
{ @
class
=
"form-control"
} })
@Html.ValidationMessageFor(model => model.Date_Modified,
""
,
new
{ @
class
=
"text-danger"
})
</div>
</div>*@
<div
class
=
"form-group"
>
<div
class
=
"col-md-offset-2 col-md-10"
>
<input type=
"submit"
id=
"sbmtInput"
value=
"Create"
class
=
"btn btn-default"
/>
@*@{Html.RenderAction(
"Index"
,
"Student_Experience"
);}*@
@Html.ActionLink(
"Cancel"
,
"Index"
,
"Student_Experience"
,
null
,
new
{ @
class
=
"btn btn-dark active"
})
</div>
</div>
</div>
}
@*<div>
@Html.ActionLink(
"Back to List"
,
"Index"
)
</div>*@
<br/><br/>
@Scripts.Render(
"~/bundles/jquery"
)
@Scripts.Render(
"~/bundles/bootstrap"
)
</body>
</html>
Reply
Answers (
1
)
How to use and implement Microsoft 365
How to use FXCOP, StyleCOP in Asp.Net Core MVC