Note that there are some explanatory texts on larger screens.

plurals
  1. POrazor view page setup with multiple sections
    primarykey
    data
    text
    <p>I looked through various tutorials, but I feel very confused on how I want to go about executing what I have in mind and want some help to clarify my thoughts. </p> <p>I will have a razor view page called <code>Profile</code>; on that profile page I have four different sections: </p> <ol> <li>Password change </li> <li>Setup password </li> <li>User name </li> <li>Biography. </li> </ol> <p>I was thinking of creating each of the four sections as a partial section and each section will have text boxes and a save button that will allow the user to add or alter information. </p> <pre><code>@model Projects.Models.PasswordModel @{ ViewBag.Title = "Profile Account"; } &lt;hgroup class="title"&gt; &lt;h1&gt;@ViewBag.Title.&lt;/h1&gt; &lt;/hgroup&gt; &lt;p class="message-success"&gt;@ViewBag.StatusMessage&lt;/p&gt; &lt;div id="wrap"&gt; &lt;div id="right"&gt; @if (ViewBag.HasLocalPassword) { @Html.Partial("_ChangePasswordPartial") } else { @Html.Partial("_SetPasswordPartial") } &lt;/div&gt; &lt;div id="left"&gt; @Html.Partial("_UserNamePartial") @Html.Partial("_BiographyPartial") &lt;/div&gt; &lt;/div&gt; </code></pre> <p>How can I properly set up the main view page and have the four sections properly displayed and functional? I got them to be displayed, but when I try to save a change I made to the username I would get an error for a different model--say the biography model. I feel like they are being connected when they shouldn't. I am really looking for a clear tutorial of how to go about this and hopefully I will be able to make one after I figure this out. </p> <p>This is my username partial</p> <pre><code>@model Project.Models.UsernameModel @using (Html.BeginForm("_UsernamePartial", "Account")) { @Html.AntiForgeryToken() @Html.ValidationSummary() &lt;p&gt;Username&lt;/p&gt; @Html.TextBoxFor(m=&gt;m.Username) &lt;button class="btn btn-small" type="submit" value="Save Username"&gt;Save&lt;/button&gt; } </code></pre> <p><strong>My controller</strong> </p> <p>GET: </p> <pre><code>public ActionResult _UsernamePartial() { var usernameModel = new UsernameModel(); using (var db = new DataContext()) { usernameModel.Nickname = (from u in db.Users where u.ID == WebSecurity.CurrentUserId select u.Username).FirstOrDefault(); } return View(usernameModel); } </code></pre> <p>POST:</p> <pre><code>[HttpPost] public ActionResult _UsernamePartial(UsernameModel usernameModel, string returnUrl) { if (ModelState.IsValid) { using (var db = new DataContext()) { User user = db.Users.FirstOrDefault(m =&gt; m.ID == WebSecurity.CurrentUserId); user.Username = usernameModel.Username; db.SaveChanges(); } return RedirectToAction("_UsernamePartial"); } return View(returnUrl); } </code></pre> <p>Your help is greatly appreciated. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload