Click here to Skip to main content
15,744,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my view


XML
<% using (Html.BeginForm()) { %>
    <%: Html.ValidationSummary(true) %>
    <fieldset>
        <legend>DoctorMaster</legend>

        <%: Html.HiddenFor(model => model.nCode) %>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cName) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cName) %>
            <%: Html.ValidationMessageFor(model => model.cName) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cHospitalName) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cHospitalName) %>
            <%: Html.ValidationMessageFor(model => model.cHospitalName) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cAddress) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cAddress) %>
            <%: Html.ValidationMessageFor(model => model.cAddress) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.nDrType) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.nDrType) %>
            <%: Html.ValidationMessageFor(model => model.nDrType) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cPhno) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cPhno) %>
            <%: Html.ValidationMessageFor(model => model.cPhno) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cMobile) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cMobile) %>
            <%: Html.ValidationMessageFor(model => model.cMobile) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cRegNo) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cRegNo) %>
            <%: Html.ValidationMessageFor(model => model.cRegNo) %>
        </div>

        <div class="editor-label">
            <%: Html.LabelFor(model => model.cEmail) %>
        </div>
        <div class="editor-field">
            <%: Html.EditorFor(model => model.cEmail) %>
            <%: Html.ValidationMessageFor(model => model.cEmail) %>
        </div>

        <p>
            <input type="submit" value="Save" />
        </p>
    </fieldset>
<% } %>






this is my action method for edit


SQL
public ActionResult Edit(int id)
       {
           var DocMstrEdit = from v in context.DoctorMasters where v.nCode == id select v;
           return View(DocMstrEdit);
       }


when i invoke edit it throws this error please help me




CSS
Server Error in '/' Application.
The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[SantramNetra.Models.DoctorMaster]', but this dictionary requires a model item of type 'SantramNetra.Models.DoctorMaster'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The model item passed into the dictionary is of type 'System.Data.Linq.DataQuery`1[SantramNetra.Models.DoctorMaster]', but this dictionary requires a model item of type 'SantramNetra.Models.DoctorMaster'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Posted
Comments
Zoltán Zörgő 5-Jul-12 7:30am    
And what is the model declaration of the view?

1 solution

It sounds like you are trying to put the results into one model but your linq query isn't returning one model. That issue will be eaten up by the var keyword. If you were to change that to be type Models.DoctorMaster instead, I think you would see the error earlier. To fix this, change your linq query to look like this:

C#
public ActionResult Edit(int id)
{
   Models.DoctorMaster DocMstrEdit = (from v in context.DoctorMasters 
                                      where v.nCode == id 
                                      select v).FirstOrDefault();
   return View(DocMstrEdit);
}


That will ensure that you only return one model into your variable. When you are expecting one model, it is always best to do this, even if you are querying a value that should only return one entry.
 
Share this answer
 
Comments
vivek shaushi 5-Jul-12 8:21am    
thankyou very much friend.........

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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