MVC: How can i refresh a partial view, which contains an Ajax.BeginForm

Posted on 2011-05-10
Last Modified: 2012-05-11

I've created an Ajax.BeginForm(in a partial view) to send information through to the controller so that it can be stored in a backend db.  When the user has clicked submit, the grid in the partial view will be updated with the information that the user has supplied.  The problem that i am facing is that the partial view is not being refreshed to display the updated grid.  What is the easiest way to do this?  Any help would be appreciated.
		public ActionResult PostComment(string CommentType, string CommentText, string ContactId)

			var contactId = new Guid(ContactId);
			Comment commentStore = new Comment();
			commentStore.CommentText = CommentText;
			commentStore.CommentTypeId = new Guid(CommentType);
			commentStore.Username = User.Identity.Name.Substring(4, User.Identity.Name.Length-4);

			CommentProvider commentProvider = new CommentProvider();
			commentProvider.CreateComment(contactId, commentStore.CommentTypeId, commentStore.CommentText, commentStore.Username);

			return Content("Added");

Open in new window

@model IList<PAConnector.Comment.Comment>
	ViewBag.Title = "Work Experience";
<div id="CommentsContainer"
	<h2>Work Experience Gained</h2>
	<div class="Comments_popup">

	@using (Ajax.BeginForm("PostComment", new AjaxOptions() { UpdateTargetId = "Comments_Result", HttpMethod = "POST" }))  {
		@Html.Label("Comment Type")
		@Html.DropDownList("CommentType", AdmissionsWeb.Helpers.CacheHelper.GetCommentTypes())
		<br />
		@Html.Label("Comment Text")
		@Html.TextArea("CommentText", new { CssClass="comment_text_area"})

		<input type="hidden" id="ContactId" name="ContactId" value=@ViewBag.ContactId />
		@Html.SubmitButton("Submit", 0, "submitButton")

	<div id="Comments_Result">
	<div id="Comments_Grid">
					<span class="Comments_Result">
				@Html.Grid(Model).Columns(c =>
	c.For(a => a.CommentText).Named("Text");
	c.For(a => a.CommentType).Named("Comment Type");
	c.For(a => a.DateAdded).Named("Date Added");
	c.For(a => a.Username).Named("User");

Open in new window

Question by:dizzy01

    Author Comment

    Increasing the points...

    Author Comment

    Anyone?  Any comments would be well appreciated: even if it's to say that what i've written makes no sense :).
    LVL 27

    Accepted Solution

    You are only returning the word added here
    return Content("Added");
    You need to return the model back to the view

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    A Change in PHP Behavior with Session Write Short Circuit ( (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now