In Asp.net MVC ,I just want to return a ModelObject to View after a postback from[HttpPost]ActionMethod, but the condtion is that ModelObject should be Same/SameType of ModelObject-Argument used in same [HttpPost]ActionMethod.
Issue :After the post back NULL ModelObjectAttributes are shown in the same view.
OtherFindings:while removing the ModelObject from the argument of [HttpPost]ActionMethod and after postbacking ,the values are shown properly in the view
Code is attached.
public ActionResult Index()
{
//TestModelClass objModel = new TestModelClass();
objModel.name = "I am from GET";
objModel.message = "GET Message successfully delivered";
return View(objModel);
}
ISSUE : This Action Method is not working.ie; "No values are shown at View" OtherFindings :Values are only shown in the View, while we are not using the "TestModelClass objModel" Argument.
[HttpPost]
[ActionName("Index")]
public ActionResult IndexPost(TestModelClass objModel)
{
enter code hereTestModelClass objModel1 = new TestModelClass();
objModel1.name = "I am from POST";
objModel1.message = "Post Message successfully delivered";
return View("Index",objModel1);
}
Model
public class TestModelClass
{
public string name { get; set; }
public string message { get; set; }
}
View
@model testApp.Models.TestModelClass
@using (Html.BeginForm("Index","Home"))
{
<table>
<tr>
**@Html.TextBoxFor(x=>x.name)**
</tr>
<tr>
**@Html.TextBoxFor(x=>x.message)**
</tr>
<tr>
<input type="submit"name="submit",value="ENTER">
</tr>
</table>
}
kindly check this issue and inform any other valid solutions are available. thanks in advance