Click here to Skip to main content
15,896,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my Index view.
HTML
@model MultipleInstance.Order

@{
    ViewBag.Title = "Index";
}


@using (Html.BeginForm("ProcessForm", "Default1", FormMethod.Post))
{
   <table>
    <tr>
        <td>@Html.LabelFor(m => m.OrderID_)</td>
        <td>@Html.TextBoxFor(m => m.OrderID_)</td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m => m.CustomerID_)</td>
        <td>@Html.TextBoxFor(m => m.CustomerID_)</td>
    </tr>
    <tr>
        <td>@Html.LabelFor(m=>m.SelectType)</td>
      
        <td>@Html.DropDownListFor(m => m.SelectType, @ViewBag.docid as SelectList, "Select document Type")</td>

    </tr>
</table>

}
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="//code.jquery.com/jquery-1.11.2.min.js" type="text/javascript"></script>
<script type="text/javascript" src="scripts/jquery-1.8.2.js"></script>
<script src="~/Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#SelectType").change(function () {
            $("#log").ajaxError(function (event, jqxhr, settings, exception) {
                alert(exception);
            });
  $.get('@Url.Action("RacersByCountryPartial")',
            { id: countrySelected }, function (data) {

            $("#container").html(data);
             });
            });
    });
 </script>

   <h3>Shipping Address</h3>

    <div id="div2">
  @Html.Partial("~/Views/_Address.cshtml",
  new ViewDataDictionary()
  {
    TemplateInfo = new TemplateInfo()
      { HtmlFieldPrefix = "ShippingAddress" } })
     </div>
     <p> <input type="submit" value="Submit1" /></p>

Here I am rendering one view and in future I want to implement somemore views. It works fine. But I am calling
JavaScript
$.get('@Url.Action("RacersByCountryPartial")',

bcs some selection is there to display view. this is my action method.
C#
[HttpGet]
      public PartialViewResult RacersByCountryPartial(string id)
      {
          Address ad = new Address();

          string id1 = id.Trim();
          if (id1 == "Passport")
              return PartialView("~/Views/_Address.cshtml", ad);
         }

Actually from here i want to render my partial view but inside action method how can i specify Templateinfo and htmlfieldprefix?

This is my _address view.
@model MultipleInstance.Address


@Html.LabelFor(m => m.Street1) @Html.TextBoxFor(m => m.Street1)
@Html.LabelFor(m => m.Street2) @Html.TextBoxFor(m => m.Street2)
@Html.LabelFor(m => m.Country) @Html.TextBoxFor(m => m.Country)
@Html.LabelFor(m => m.PostalCode) @Html.TextBoxFor(m => m.PostalCode)




This is my model. Order.cs
C#
public partial class Order
    {
        public int Id { get; set; }
        public string OrderID_ { get; set; }
        public string CustomerID_ { get; set; }
        public string SelectType { get; set; }
        public Address ShippingAddress { get; set; }

    }
Posted
Updated 21-Feb-16 22:43pm

1 solution

You should use @{Html.RenderAction("Category","Home");} to load your partial.
Please refer below link.
RenderPartial vs RenderAction vs Partial vs Action in MVC Razor

Hopefully, it will work ...!
 
Share this answer
 

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