Basically all I am trying to do is have a View post back to it’s own post action method. I want the action method to update a simple value and have the view then display the new value. Below is some code snippets. The post action method receives the value from the textbox well enough but after updating this value the view does not display the new value:
View:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="user_form" style="width: 600px; margin-top: 50px">
<div class="user_form_header">
Default Distribution List
</div>
<% using (Html.BeginForm())
{ %>
<div>
<%= Html.TextBoxFor( model => model.CurrentPageIndex) %>
<input type="submit" name="submitButton" value="Send" />
</div>
<% } %>
</div>
</asp:Content>
Controller:
public ActionResult Index()
{
DefaultDistributionListViewModel model = new DefaultDistributionListViewModel();
model.CurrentPageIndex = 1;
return View(model);
}
[HttpPost]
public ActionResult Index(DefaultDistributionListViewModel model, string submitButton)
{
// repopulate the model
model.CurrentPageIndex = model.CurrentPageIndex + 1;
return View(model);
}
Controller:
public int CurrentPageIndex { get; set; }
Thanks,
In your HttpPost method, after you update the model.CurrentPageIndex and return View, Its gonna fire you HttpGet method where you reassign it.
Perhaps pass in a default parameter in your “Get” request.
// This sets a ‘default’ value as of c# 3 I believe
// If not theres a [Default] attribute you can use as well as int? page