如何在控制器中的action方法中指定模板字段? [英] How to specify template field inside the action method in an controller?

查看:75
本文介绍了如何在控制器中的action方法中指定模板字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的索引视图。

This is my Index view.

@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

$.get('@Url.Action("RacersByCountryPartial")',



bcs有些选项可以显示视图。这是我的行动方法。


bcs some selection is there to display view. this is my action method.

[HttpGet]
      public PartialViewResult RacersByCountryPartial(string id)
      {
          Address ad = new Address();

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



实际上从这里我要渲染我的部分观点,但内部行动符合如何指定Templateinfo和htmlfieldprefix?



这是我的_address视图。

@model MultipleInstance.Address


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)






@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)






这是我的模特。 Order.cs



This is my model. Order.cs

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; }

    }

推荐答案

document ).ready( function (){
(document).ready(function () {


< span class =code-string>#SelectType)。change( function (){
("#SelectType").change(function () {


#log)。ajaxError( function (event,jqxhr,settings,exception){
alert(exception);
});
("#log").ajaxError(function (event, jqxhr, settings, exception) { alert(exception); });


这篇关于如何在控制器中的action方法中指定模板字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆