Reputation: 23
I have two Model Class
public partial class EndUser
{
public EndUser()
{
this.Mobiles = new List<Mobile>();
}
public virtual long Id { get; set; }
public virtual string FullName { get; set; }
[DataType(DataType.Password)]
public virtual string UserPassword { get; set; }
public virtual string Email { get; set; }
public virtual IList<Mobile> Mobiles { get; set; }
public partial class Mobile
{
public virtual long Id { get; set; }
public virtual string Number { get; set; }
public virtual EndUser EndUser { get; set; }
}
My controller
public ActionResult CreateClient()
{
return View("CreateClient");
}
Scaffold Template Create My view
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
<legend>EndUser</legend>
<div class="editor-label">
@Html.LabelFor(model => model.FullName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.FullName)
@Html.ValidationMessageFor(model => model.FullName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.UserPassword)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserPassword)
@Html.ValidationMessageFor(model => model.UserPassword)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
But I want to add my Client Mobile From this view. How can i create multiply(unknown) text field to add mobile numbers? If client have more then one mobile number he can add more textbox by clicking "Add More Number" button. I cant create textbox for mobile number field.
Please help me out. Im new in MVC.
Upvotes: 1
Views: 1689
Reputation: 3031
You can resume it in a few steps.
@{Html.RenderPartial("DynamicMobileForm", Model);}
this will render this section only.When the page loads, will render your partial section only, adding a new textbox, and when you submit it, will automatically post it inside your Mobiles Array.
Hope it helps.
Upvotes: 0