简体   繁体   English

PartialView Navigation不返回参数

[英]PartialView Navigation not returning parameters

I've setup a partialview to handle navigation throughout multiple views. 我已经设置了partialview以处理整个多个视图中的导航。 Some of these views use a different model so I'm passing that model in like this 这些视图中的一些使用了不同的模型,所以我像这样传递了该模型

@Html.Partial("~/Views/Navigation/_PartialTabs.cshtml", new xxx.OpenAccess.OBProfiles())

It load up my partialview just fine 它加载了我的partialview就好了

@using xxx.Helpers;

@model xxx.OpenAccess.OBProfiles
<ul class="nav nav-tabs">
<li role="presentation" class="@Html.IsActive("Edit", "OBProfile")">@Html.ActionLink("Edit", "Edit", "OBProfile", new { id = Model.ProfileID }, null)</li>
<li role="presentation" class="@Html.IsActive("Index", "OBProfileTasks")">@Html.ActionLink("Tasks", "Index", "OBProfileTasks", new { id = Model.ProfileID }, null)</li>
<li role="presentation"><a href="#">Messages</a></li>

However when I mouse over the links, the parameters (Model.ProfileID) return 0 regardless of what screen i'm on. 但是,当我将鼠标悬停在链接上时,无论我在什么屏幕上,参数(Model.ProfileID)都返回0。 So the tab URLs look like this http://localhost:55129/OBProfileTasks/Index/0 因此标签网址看起来像这样http://localhost:55129/OBProfileTasks/Index/0

What am I missing that it isn't returning the /Number of whatever profileid ive selected? 我想念的是,它没有返回所选配置文件的/Number吗?

You need to prepopulate OBProfiles. 您需要预填充OBProfile。 Here are two ways: 有两种方法:

Constructor: 构造函数:

In the OBProfiles class add: 在OBProfiles类中添加:

public OBProfiles(){
ProfileID = *some value*;
}

Static method: 静态方法:

public static OBProfiles GetProfiles(){
return new OBProfiles{ProfileId = *Some value*};
}

The for static method call: for静态方法调用:

@Html.Partial("~/Views/Navigation/_PartialTabs.cshtml", OBProfiles.GetProfiles())

I believe TheDizzle hit the nail on the head. 我相信TheDizzle击中了钉子。 When you pass the model in as new, you're passing in a clean version of that model. 当您作为新模型传入时,您将传入该模型的全新版本。 Try just passing the model in without using the new keyword. 尝试仅在不使用new关键字的情况下传递模型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM