0

I have one Asp.net MVC3 page which renders details of a Mobile. This page also hosts a comment form which is rendered using Comment model. One field named Name i.e Mobile.Name and Comment.Name is common in both the models.

In the final output I always see Comment.Name text box filled with the value of Mobile.Name. Not sure why this is happening.

Exact problem can be seen at below link.. check the comments tab

problem url

Edit Comment form is rendered using a partial view which is something like below :

@using (Ajax.BeginForm("Savecomment", new AjaxOptions() { UpdateTargetId = "FormContainer" , OnSuccess = "$.validator.unobtrusive.parse('form');" }))
{
       @Html.HiddenFor(m => m.MobileId)
        <div class="row">
        <div class="five columns">
          <label >Your name:</label>
          @Html.TextBox("Name"," ")
          @Html.ValidationMessage("Name")
        </div>
        </div>
3
  • 1
    the code will be helpful Commented Jul 22, 2012 at 5:02
  • 1
    There's no controller code or complete view code to see your issue it's all a guess Commented Jul 22, 2012 at 5:12
  • You need to include more information. How exactly is your full model defined? How are you rendering both Mobile and Comment? Commented Jul 22, 2012 at 5:20

1 Answer 1

1

Your problem is more than likely related to how you are rendering you Partial View. I am assuming you have a parent model that contains both Mobile and Comment? You are passing the Comment model to the Partial View? Because of this, the partial view is rendering the name of the field as if it were the primary model.

I would suggest using an EditorTemplate to render your Comment and Mobile rather than partial views. Editor Templates are more aware of their context than Partial Views are.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mystere Man for the explanation. My approach is very similar to what you have mentioned. I have one Mobile model which contains a collection of comment objects.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.