[RESOLVED]CRUD, create and update functionality on same view : asp.net mvc2 + EF


Hello all,

I am a new bee and is making web application in visual studio 2010 using mvc2 + entity framework.

i have a situation in which i want to put both operations i.e create user / update user at same view, i have also tried attaching relevant picture where i have made two portions one for create user and second for manage users.

My ‘create user’ fields are at top of website and when user click ‘create button’ page got refreshed and all enlisted users gets displayed on same view under second portion ‘manage users’ showing link to edit/delete them.

i want that when i click on edit link, that particular entity fields get populated on same view in 1st portion ‘create user’ where i can modify them and press ‘update button’

I have tried to explain my scenario in detail, kindly if you feel any difficulty in understanding allow me to explain in more detail, looking for urgent response. thanks

    <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Admin.Master" Inherits="System.Web.Mvc.ViewPage" %>
    <%@ Import Namespace="MyNamespace"  %>

    <h4>Create New User</h4>
    <form method="post" action="/Lignum/CUser">
       <label for="inputEmail3">Full Name</label>
       <input type="text" name="Fullname" id="txtFullname" >
       <label for="inputEmail3">Email</label>
       <input type="email" name="Email" id="Email1">
       <button id="btnCUser" class="btn btn-primary">Create</button>
    <h4>Manage Users</h4>
    <% int i=0;
    foreach (MyWebsite.Models.User objUser in ViewData.Model as IEnumerable<MyWebsite.Models.User>)
         <td><%= ++i%></td>
    	 <td><%= objUser.Fullname%></td>
    	 <td><%= objUser.Email%></td>
             <a href="/Controller/Edit/<%= objUser.UserId %>">Edit</a>

    public ActionResult Index()
        return View("UserMgt", _repositoryUser.SelectAll());
    public ActionResult Edit(object Id)
        if (Id != null && Id.ToString().Trim().Length > 0)
            int param = int.Parse(Id.ToString());
            return View("UserMgt", _repositoryUser.SelectByID(Id));
        return View("404");

Dear Fellows,

can i get any assistance from this forum ?

Maybe you can return a view in your edit that looks exactly the same as your page and pass your data to that view. Or, you might want to display your create and edit forms as partial views and display the appropriate partial view depending on the user’s
choice. You can attach a javascript onclick on your Edit links which calls a function that would display your Edit partial view and populate the fields with data from your table.

Leave a Reply