Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3236842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T17:40:06+00:00 2026-05-17T17:40:06+00:00

Greeting Everyone, I’m having a little trouble with a partial view I’m using as

  • 0

Greeting Everyone,

I’m having a little trouble with a partial view I’m using as an edit form. Aside from the hidden elements in the form, the model is null when passed to my EditContact post controller.

I should add, I realize there’s a more seamless way to do what I’m doing using AJAX, but I think if I can solve the clunky way first it will help me understand the framcework a little better.
Here’s my EditContact partial view:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<WebUI.DataAccess.CONTACT>" %>
<div id="contactPartial-<%= ViewData.Model.id %>">
    <% Html.EnableClientValidation(); %>
    <% using (Html.BeginForm("EditContact", "Investigator"))
       { %>
    <%= Html.HiddenFor(Model => Model.id) %>
    <%= Html.HiddenFor(Model => Model.investId) %>
    <table id="EditContact-<%= ViewData.Model.id %>" width="100%">
        <tr>
            <th colspan="4">
                <b>New Contact</b>
            </th>
        </tr>
        <tr>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.type)%></b><br />
                <%= Html.EditorFor(Model => Model.type, null, "contactType-" + ViewData.Model.id)%><br />
                <%= Html.ValidationMessageFor(Model => Model.type) %>
            </td>
        </tr>
        <tr>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.salutation)%></b><br />
                <%= Html.EditorFor(Model => Model.salutation, null, "contactsalutation-"+ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.firstName)%></b><br />
                <%= Html.EditorFor(Model => Model.firstName, null, "contactFirstName-"+ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.middleName)%></b><br />
                <%= Html.EditorFor(Model => Model.middleName, null, "contactMiddleName-"+ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.lastName)%></b><br />
                <%= Html.EditorFor(Model => Model.lastName, null, "contactLastName-"+ViewData.Model.id)%><br />
                <%= Html.ValidationMessageFor(Model => Model.lastName)%>
            </td>
        </tr>
        <tr>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.title)%></b><br />
                <%= Html.EditorFor(Model => Model.title, null, "contactTitle-"+ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.phone)%></b><br />
                <%= Html.EditorFor(Model => Model.phone, null, "contactPhone="+ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.altPhone)%></b><br />
                <%= Html.EditorFor(Model => Model.altPhone, null, "contactAltPhone-" + ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.fax)%></b><br />
                <%= Html.EditorFor(Model => Model.fax, null, "contactFax-" + ViewData.Model.id)%>
            </td>
        </tr>
        <tr>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.email)%></b><br />
                <%= Html.EditorFor(Model => Model.email, null, "contactEmail-" + ViewData.Model.id)%>
            </td>
            <td>
                <b>
                    <%= Html.LabelFor(Model => Model.comment)%></b><br />
                <%= Html.EditorFor(Model => Model.comment, null, "contactComment-" + ViewData.Model.id)%>
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
        <tr>
            <td>
                <input type="submit" value="Save" />
            </td>
            <td>
                <button id="<%= ViewData.Model.id %>" class="contactEditHide">
                    Cancel</button>
            </td>
            <td>
            </td>
            <td>
            </td>
        </tr>
    </table>
    <% } %>
</div>

When the Edit contact post controller is passed the model only id and investId have values; everything else is null. Here’s how I’m rendering the partial view in my Details view:

   <table width="100%">
    <tr>
        <th colspan="7">
            <b>Contacts</b>
        </th>
        <th id="contactButton" class="button">
            <button id="showEditContact-0" type="button" class="contactEditShow">New Contact</button>
        </th>
    </tr>
    <tr>
        <th>
            Type
        </th>
        <th>
            Name
        </th>
        <th colspan="2">
            Title
        </th>
        <th>
            Prim. & Alt. Phone
        </th>
        <th>
            Fax
        </th>
        <th colspan="2">
            Comment
        </th>
    </tr>
    <% for (int i = 0; i < Model.CONTACTs.Count; i++)
       { %>           
    <tr id="contactRow-<%= Model.CONTACTs[i].id %>" class="contactRow">
        <td>
            <%= Html.Encode(Model.CONTACTs[i].type)%>
        </td>
        <td>
            <%= Html.Encode(Model.CONTACTs[i].salutation)%>
            <%= Html.Encode(Model.CONTACTs[i].firstName)%>
            <%= Html.Encode(Model.CONTACTs[i].middleName)%>
            <%= Html.Encode(Model.CONTACTs[i].lastName)%>
            <br />
            <a href="mailto:<%= Html.AttributeEncode(Model.CONTACTs[i].email) %>">
                <%= Html.Encode(Model.CONTACTs[i].email)%></a>
        </td>
        <td colspan="2">
            <%= Html.Encode(Model.CONTACTs[i].title)%>
        </td>
        <td>
            Prim:<%= Html.Encode(Model.CONTACTs[i].phone)%><br />
            Alt:<%= Html.Encode(Model.CONTACTs[i].altPhone)%>
        </td>
        <td>
            <%= Html.Encode(Model.CONTACTs[i].fax)%>
        </td>
        <td>
            <%= Html.Encode(Model.CONTACTs[i].comment)%>
        </td>
        <td>
            <button id="<%= Model.CONTACTs[i].id %>" type="button" class="contactEditShow">Edit Contact</button>
        </td>
    </tr>
    <tr>
        <td colspan="8">
            <% Html.RenderPartial("EditContact", Model.CONTACTs[i]); %>
        </td>
    </tr>
    <% } %>
</table>

My details view is strongly tyed to an INVESTIGATOR model:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebUI.DataAccess.INVESTIGATOR>" %>

As you can see above, my partial view is strongly typed to a CONTACTS model.

I ran into a similar problem with Model binding when, in a view, I was trying to allow for the editing all layers of an address at one time and fixed it by indexing the model, similar to the Details view above. It seems like I need to do the same thing in my partial view to ensure Model binding, but I’m not sure how to achieve this (having syntax issues).

Of course, I could be off here an need a new solution in general!
Let me know if you need more detail! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T17:40:07+00:00Added an answer on May 17, 2026 at 5:40 pm

    Why are you using

    <%= Html.EditorFor(Model => Model.salutation, null, "contactsalutation-"+ViewData.Model.id)%>
    

    If you use it simply like this

    <%= Html.EditorFor(Model => Model.salutation) %>

    It should be working.

    In order to map your model, your control need to have the same id as there name, and the third parameter you’re using changes your control id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greeting Everyone I'm trying to compile and run a multi-language code in C, C++
the following code #include <iostream> using namespace std; int main(){ char greeting[50] = goodmorning
Greetings everyone. Having an issue compiling my script containing the following function. Three errors
Greetings everyone: I would love to get some information from a huge collection of
Greetings Everyone I am new in asp.net and i'm using RadControls for Asp.net Ajax
Greeting. How to enable or disable asp.net DropDownList control using jquery when checking an
Greeting, I listed two examples of using style propriety for asp.net control. what is
Greetings everyone- In my code below I'm trying to add a Row from an
Greetings everyone, I'm having a very strange problem. I've created a DateTextBox which automaticly
Greeting Overflowers, I am asked to code an email tracker using PHP. Email clients

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.