Htm.ActionLink对象引用未设置为对象的实例

时间:2011-09-18 00:28:01

标签: asp.net asp.net-mvc asp.net-mvc-3

我得到了这个例外,我不确定我是否也以正确的方式做到了,

异常详细信息:System.NullReferenceException:未将对象引用设置为对象的实例。

视图

@model BattleNet.API.WoW.Character


@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<fieldset>
    <legend>Character</legend>
 <div class="editor-label">
        @Html.LabelFor(model => model.Realm)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Realm)
        @Html.ValidationMessageFor(model => model.Realm)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
        @Html.ValidationMessageFor(model => model.Name)
    </div>

    <p>
        <input type="submit" value="Search" />
    </p>
</fieldset>

}

@Html.ActionLink("Search", "WoW", "Home", new { realm = Model.Realm, chara = Model.Name }, null)    

错误

Exception Details: System.NullReferenceException: Object reference not set to an instance of an  object.
Line 38: @Html.ActionLink("Search", "WoW", "Home", new { realm = Model.Realm, chara =   Model.Name }, null)    

控制器

    public ActionResult WoW(string realm, string chara)
    {
        var getchar = client.GetCharacter(realm, chara);

        return View(getchar);
    }

任何有关我在这里做错的提示都会非常感激

1 个答案:

答案 0 :(得分:0)

第三个参数是object routeValues

@Html.ActionLink("TextToBeDisplayed","ActionName",object routeValues, object htmlAttributes)

所以在你的情况下它变成了

@Html.ActionLink("Search", "WoW",new { controller = "Home", chara = Model.Name, realm = Model.Realm  }, null)