Save data from diffrent partial views on Single view on single button submit in mvc 3

i have three classes

  public partial class User
{          
    public string No_ { get; set; }      
    public string LastName { get; set; }   
    public virtual ICollection<Login> Logins { get; set; }  
    public virtual ICollection<Education> Educations { get; set; }
} 
public partial class Education
{
    public string No_ { get; set; }
    public string UserId { get; set; }
    public string Degree { get; set; }
    public string Institution { get; set; }
    public string Percentage { get; set; }
}
public partial class Login
{        
    public string No_ { get; set; }     
    public string UserId { get; set; }       
    public string Username { get; set; }
    public string Password { get; set; }
    public virtual User User { get; set; }
}

i have made three partial views for three diffrent models and made it render into a page as below

@{
ViewBag.Title = "Register";
Layout = "~/Views/Shared/BlankLayout.cshtml";
 }
 <h2>
Register</h2>@using (@Html.BeginForm())
{
      @Html.Partial("LoginPartialView")

      @Html.Partial("UserPartialView")

      @Html.Partial("ProfessionPartialView")

      <section>
          <div>
             <button class="reset">Reset</button>
             <button class="submit" name="submit" value="Submit">Submit</button>
          </div>
   </section>
}

what i want is when i click the submit button all the data from the partial views should get to [httppost] where i can save the data to User,Education,Login Tables . how to get the data into the controller which has http post controller like :

[HttpPost]
    public ActionResult Register(?,?,?)
    {
        context.Logins.Add(LoginObject);
        context.Educations.Add(EducationObject);
        context.Professions.Add(ProfessionObject);
        return View();
    }

i just want to know how to get the above partial views data into the httppost controller so that i can save the data as mentioned above

i am pretty much novice in Mvc 3 Pardon me if i am making no sense while i am asking . please guide me along with

Answers


Instead of partials I would recommend you using editor templates. Here's an example how you could write a form that will save the User object:

@model User
@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/BlankLayout.cshtml";
}
<h2>
Register</h2>
@using (@Html.BeginForm())
{
    @Html.EditorFor(x => x.No_)
    @Html.EditorFor(x => x.LastName)

    @Html.EditorFor(x => x.Logins)
    @Html.EditorFor(x => x.Educations)

    <section>
        <div>
            <button class="reset">Reset</button>
            <button class="submit" name="submit" value="Submit">Submit</button>
        </div>
   </section>
}

and then the 2 corresponding editor templates:

~/Views/Shared/EditorTemplates/Login.cshtml:

@model Login
... some input fields for the login

~/Views/Shared/EditorTemplates/Education.cshtml:

@model Education
... some input fields for the education

and the controller action:

[HttpPost]
public ActionResult Register(User model)
{
    // the model object will be correctly populated from the default model binder
    // here we can save it
    return View(model);
}

Need Your Help

How to call java code from Go without invoking the JVM for every call?

java go

Is it possible (and if so, what is the recommended way) to call java code from Go, without the need to start the JVM for every function call?

mysql “or” order of query operations

php mysql laravel query-optimization eloquent

So I'm working with laravel 3 which use eloquent ORM on a mysql database. I've got a function that makes repeated round trips to the SQL server, and I've got it working with my limited test cases, ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.