I have class
public class Class2
{
public string myName { get; set; }
public string phone { get; set; }
public jInformation jf { get; set; }
public Class2()
{
}
}
public class jInformation
{
public string name { get; set; }
public string display { get; set; }
public jInformation()
{
}
}
Now my action method is
public ActionResult Test()
{
Class2 oClass = new Class2();
return View("ViewPage1",oClass);
}
And post is
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public void Test(Class2 oClass)
{
String sTemp = oClass.myName;
String sp = oClass.phone;
}
I want to create a stongley typed view with ViewContent As “Edit”. So when i create strongly typed view, it just create text box for myName and phone property. How can i create textbox for jINformation class? I am using MVC1 and newbie to MVC world…….
My CustomModel Binder looks like
public class Class2ModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var request = controllerContext.HttpContext.Request;
return new Class2()
{
myName = request.Form.Get("myName"),
phone = request.Form.Get("phone"),
jf = new jInformation { name = request.Form.Get("name"), display = request.Form.Get("display") }
};
}
}
I registered it with application_start. Now question is, what i should pass on get and post method?
My previous comment was a bit wrong. The default Model Binder will work for your ‘Class2’.
Here i tested and it works.
The Controller code
The view code (Just a form against your Model)