如何将列表项从控制器传递到视图

时间:2019-04-30 16:31:26

标签: view model controller

我在控制器中有一个局部视图和一个动作方法。在动作方法中,我具有要绑定的不同列表,在我的第一个div中,我仅获得一个值,但在第二个列表中,我可能会获得多个值,需要将它们传递给他们。当我试图让他们查看时,我遇到了错误。如何从控制器传递列表数据以在MVC中查看?

我正在尝试通过对每个循环使用来尝试,但是它不起作用

Dim properties
loadCustomActionData properties
MsgBox ("INSTALLDIR: " & properties("INSTALLDIR"))

' =====================
' Decode the CustomActionData
' =====================
Sub loadCustomActionData( ByRef properties )
    Dim data, regexp, matches, token
    data = Session.Property("CustomActionData")

    Set regexp = new RegExp
    regexp.Global = true
    regexp.Pattern = "((.*?)='(.*?)'(;|$))"

    Set properties = CreateObject( "Scripting.Dictionary" )
    Set matches = regexp.Execute( data )
    For Each token In matches
        properties.Add token.Submatches(1), token.Submatches(2)
    Next
End Sub

控制器

@foreach(var item in Model)
{
                @if ((item.Name1 != null))
                {
                    <p> @item .Name1 </p>
                }
                else
                {
                    <p> Not Available</p>
                }
}

查看-

public ActionResult ViewInfo(long Id = 0)
        {
            UviewAhsPhMemberInfoProxyStub model = new UviewAhsPhMemberInfoProxyStub();
            try
            {

                esParameters parameters = new esParameters();
                parameters.Add("Id", Id);
                List<UviewBasicdataProxyStub> lstbasicdata = _resource.Activity.GetPhMemberInfo(parameters, timeDictionary).Result;
                List<UviewAdditionaldataProxyStub> lstadditionaldata = _resource.Activity.GetPhContactInfo(param).Result;
                if (lstbasicdata.Count > 0)
                {
                    var basicdata= lstbasicdata[0];
                    model.Name1 = basicdata.Name1.SetStringOrNotAvailable("Not Available");
                    model.Name2 = basicdata.Name2.SetStringOrNotAvailable("Not Available");
                    model.Name3 = basicdata.Name3.SetStringOrNotAvailable("Not Available");
                    model.Name4 = basicdata.Name4.SetStringOrNotAvailable("Not Available");           
                }

                if (lstadditionaldata.Count > 0)
                {
                    var additionaldata = lstadditionaldata[0];
                    model.Number1 = ConactInfo.Number1.SetStringOrNotAvailable("Not Available");
                    model.Number2 = ConactInfo.Number2.SetStringOrNotAvailable("Not Available");
                    model.Number3 = ConactInfo.Number3;
                    model.Number4 = ConactInfo.Number4.SetStringOrNotAvailable("Not Available"); //county
                    model.Number5 = ConactInfo.Number5.SetStringOrNotAvailable("Not Available");
                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return PartialView(model);
        }

0 个答案:

没有答案