@Html.RenderAction with Ajax Form ASP.NET Mvc3 c#

本文关键字:NET Mvc3 ASP Form RenderAction with Ajax @Html | 更新日期: 2023-09-27 18:21:45

我有一个场景,当控件呈现时,我需要一些代码设置。我有一个小部件,它将在许多页面上使用,称为QuickRate:

我试着在我的cshtml文件中这样称呼它:

<div class="dragbox" id="quick-rate">
<h2>Retrieve a Quick Rate</h2>
@Html.Action("Create", "QuickRate")
</div>

然后在QuickRateController.cs上创建。我有:

public ActionResult Create()
{
var model = new QuickRateModel();
    model.Products = currentUser.GetProducts(dataRepository).ToSelectList(p => p.ProductId, p => p.ProductName);
return View("QuickRateResult", model);
}

然后我有一个QuickRatePartial.cshtml文件,其中包含以下内容:

@model Project.Web.Models.QuickRateModel
@{
    Layout = "";
    AjaxOptions options = new AjaxOptions()
    {
        HttpMethod = "Post",
        UpdateTargetId = "quick-rate-content"
    };
}
<div class="clearfix">
    @using (Ajax.BeginForm("GetQuickRate", "QuickRate", null, options, new { @id="quick-rate-form" }))
 {
        <fieldset>
          @Html.DropDownListFor(model => model.ProductId, Model.Products)
          @Html.ValidationMessageFor(model => model.ProductId)
         <select data-val="true" name="DropDown1" data-bind="
                                options: Items1,
                                optionsText :'ItemName',
                                value: SelectedName
                                ">
                            </select>
        <select data-val="true" name="DropDown2" id="DropDown2" data-val-required="Please select an Item." data-bind="
        options: SelectedItem().MoreItems,
        optionsText: 'Text',
        optionsValue: 'Text',
        value: MoreItem,
        optionsCaption: 'Select One'
        "></select>
        <div class="clearfix">
            @Html.ValidationMessageFor(model => model.MoreItems)
        </div>
        <div>
            <input type="submit" value="Get Quick Rate" />
        </div>
        <div id="quick-rate-content"></div>
        </fieldset>
 }
</div>

尽管我尽力了,但我根本无法使表单呈现出来。。只是想知道你有什么建议吗?

干杯!

@Html.RenderAction with Ajax Form ASP.NET Mvc3 c#

您已经将文件命名为quickratepartial.chtml,但在操作中,您正在寻找一个名为quickrate result的视图。这是正确的吗?