• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1029
  • Last Modified:

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

Hi,

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.
[HttpPost]
		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>


	<div id="Comments_Result">
	</div>
	
	<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");
}
						)
			</span>
	</div>
</div>

Open in new window

0
dizzy01
Asked:
dizzy01
  • 2
1 Solution
 
dizzy01Author Commented:
Increasing the points...
0
 
dizzy01Author Commented:
Anyone?  Any comments would be well appreciated: even if it's to say that what i've written makes no sense :).
0
 
Sammy AgeilCommented:
You are only returning the word added here
return Content("Added");
You need to return the model back to the view
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now