Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I need to perform Create, List, Update in Single screen insted of separete views in Mvc.
Can anybody suggest how to do this. I tried with partial view but could not accomplish the task.
Pls help

this is my view
XML
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<MvcMaster.Models.Mast_Lab>>" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Index</title>
</head>
<body>
    <table>
    <tr>
        <%Html.RenderPartial("Create"); %>
    </tr>
        <tr>
            <th></th>
            <th>
                iMast_Lab_id
            </th>
            <th>
                cLab_Name
            </th>
            <th>
                dCreate_dt
            </th>
            <th>
                bActive
            </th>
        </tr>

    <% foreach (var item in Model) { %>

        <tr>
            <td>
                <%: Html.ActionLink("Edit", "Edit", new { id=item.iMast_Lab_id }) %> |
                <%: Html.ActionLink("Details", "Details", new { id=item.iMast_Lab_id })%> |
                <%: Html.ActionLink("Delete", "Delete", new { id=item.iMast_Lab_id })%>
            </td>
            <td>
                <%: item.iMast_Lab_id %>
            </td>
            <td>
                <%: item.cLab_Name %>
            </td>
            <td>
                <%: String.Format("{0:g}", item.dCreate_dt) %>
            </td>
            <td>
                <%: item.bActive %>
            </td>
        </tr>

    <% } %>

    </table>



</body>
</html>



and this is controller class
private LabDataContext db = new LabDataContext();
public ActionResult Index()
{
var lb = (from l in db.Mast_Labs select l);//.FirstOrDefault();
return View(lb);

//Models.Mast_Lab DocMstrEdit = (from v in db.Mast_Labs

// select v).FirstOrDefault();
//return View(DocMstrEdit);
}
public ActionResult Create()
{
return View();
}
public ActionResult CreateNew(string LabName)
{
var lb = new Mast_Lab();
lb.cLab_Name=LabName;
lb.dCreate_dt=DateTime.Now;
lb.bActive=1;
db.Mast_Labs.InsertOnSubmit(lb);
db.SubmitChanges();
return View();
}
Posted
Updated 9-Jul-14 0:17am
v2
Comments
Raje_ 9-Jul-14 5:34am    
With partial view It can be done easily. where did you stuck?
Divya RS 9-Jul-14 6:10am    
i got tis error 'The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[MvcMaster.Models.Mast_Lab]', but this dictionary requires a model item of type 'MvcMaster.Models.Mast_Lab' while returning all records for list, if i return single record then its working fine

1 solution

 
Share this answer
 
Comments
Divya RS 10-Jul-14 2:26am    
the problem is partialview postback is not getting to the corresponding action(CreateNew), instead it takes to the parent view action (Index)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900