Link to home
Start Free TrialLog in
Avatar of dizzy01
dizzy01Flag for United Kingdom of Great Britain and Northern Ireland

asked on

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

Avatar of dizzy01
dizzy01
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Increasing the points...
Avatar of dizzy01

ASKER

Anyone?  Any comments would be well appreciated: even if it's to say that what i've written makes no sense :).
ASKER CERTIFIED SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial