在MVC 5中更新部分视图 [英] Updating a Partial View in MVC 5

查看:82
本文介绍了在MVC 5中更新部分视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试加载部分视图时出现错误,该视图应在MVC应用程序的创建视图上显示一个列表.该列表基于一个值,该值将来自值列表的下降控件.

I am getting an error when trying to load a partial view that should display a list on the create view of the MVC app. The list is based on a value will come from a list of values drop control.

在创建视图上没有选择,因此列表为空,并且在用户在MVC创建视图中选择一个值后将需要刷新该列表.

On create view there is no selection so the list is empty and will need to refreshed after the user selects a value while in the MVC create view.

我在这个问题上遵循了公认的答案,但出现了错误:

I followed the accepted answer on this question and got errors:

更新PartialView mvc 4

但是我对所讲的内容有一些疑问.

But I have some questions about what is being said.

有人说:有一些方法可以做到.例如,您可以使用jQuery:."他显示了Java查询.

Someone said: "There are some ways to do it. For example you may use jQuery:" and he shows the Java query.

但是他还显示了另一种方法,并说:如果您在操作中使用逻辑UpdatePoints()来更新点"

But he also shows another method and says: "If you use logic in your action UpdatePoints() to update points"

[HttpPost]
public ActionResult UpdatePoints()
{    
   ViewBag.points =  _Repository.Points;
   return PartialView("UpdatePoints");
 }

我收到以下错误

对于"System.Controllers.RController"中的方法"System.Web.Mvc.ActionResult UpdateList(Int32)",参数字典包含一个非空类型"System.Int32"的参数"ID"的空条目.可选参数必须是引用类型,可为空的类型,或者必须声明为可选参数.参数名称:参数

The parameters dictionary contains a null entry for parameter 'ID' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult UpdateList(Int32)' in 'System.Controllers.RController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters

我不知道这个错误是什么意思

I have no clue what this error means

因此在创建视图中:

        <div class="col-sm-6">

            <div class="form-horizontal" style="display:none" id="PVList">

                @{ Html.RenderAction("UpdateList");}

            </div>
        </div>

在控制器中的create动作下作为其自身功能

In controller under the create action as its own function

    [HttpGet]
    public ActionResult UpdateList(int ID)
    {

        if (ID != 0)
        {
            ViewBag.List = Get_List(ID);
            return PartialView("PV_List");

        }
        else
        {
            ViewBag.List = "";
            return PartialView("");
        }


    }

以及为视图包功能创建列表的功能:

And the function that makes the list for the view bag function:

private List<SQL_VIEW_LIST> Get_List(int ID)
        {

            return db.SQL_VIEW_LIST.Where(i => i.ID == ID).ToList();
        }

用于值列表的JavaScript会在值列表下拉列表中:该控件还控制在具有数据的情况下打开列表的可见性:

The JavaScript for the for the list of values drop down list of values: That also controls turning on the visibility of the list when it has data:

    //Fire The List to make visible after list values select 
    $(document).ready(function () {
        $('#RES_VEH_ID').change(function ()
        {

            $("#PV_List").show(); // Shows Edit Message
            $.post('@Url.Action("PostActionTo_Partial","Create")').always(function()
                   { ('.target').load('/Create'); })

        });
    })

还有谁知道这个字符串是什么意思吗? "PostActionTo_Partial"

Also does anyone know what this string mean: ? "PostActionTo_Partial"

还有谁知道ViewBag.points = _Repository.Points;的含义吗?我得到了视图包部分,但它是_Repository.Points;.我不明白的部分.任何人都对那里发生的事情有任何想法吗?

Also does anyone know what this means ViewBag.points = _Repository.Points; I get the view bag part but it's the _Repository.Points; part that I don't understand. Any one have any ideas of what is going on there?

推荐答案

我不明白您要怎么做.但我会尽力回答.

I can't understand what do you try to do. But i'll try to answer.

我不知道这个错误是什么意思.

I have no clue what this error means.

此错误表示模型联编程序找不到操作方法的参数"ID"

This error means that model binder can't find parameter "ID" for action method

public ActionResult UpdateList(int ID)

因为您没有为此方法发送任何参数: 您可以尝试以下方法:

Because you don't send any parameter for this method: You can try this:

@{ Html.RenderAction("UpdateList", new {ID="value"});}

或者您可以在方法中设置默认值:

Or you can set default value in your method:

public ActionResult UpdateList(int ID=value)

或使"ID"为空:

public ActionResult UpdateList(int? ID)

还有谁知道这个字符串是什么意思吗? "PostActionTo_Partial"

Also does anyone know what this string mean: ? "PostActionTo_Partial"

这是您控制器中的动作名称"

this is "action name" in yor controller

还有谁知道ViewBag.points =的意思吗? _Repository.Points;

Also does anyone know what this means ViewBag.points = _Repository.Points;

这意味着分配动态对象"VivBag.points"的数据以将其传输到视图中

it means assigning dynamic object "VivBag.points' data to transfer them into view

这篇关于在MVC 5中更新部分视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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