Aht
Aht

Reputation: 593

Passing parameters into htm.actionlink giving strange result

I have a with passing parameters into htm.action link

My code :

Controller :

    public ActionResult NewsInfo(string id)
    {
        ViewBag.Messege = "News Detail";

        return View(new NewsInfoModel(id));
    }

Model :

public class NewsInfoModel
{
    public NewsDto News { get; private set; }
    public List<ComentDto> comentList { get; private set; }

    public NewsInfoModel(string id)
    {
        comentList = new Coment().MakeComentListForNews(id);
        News = new NewsDao().GetNewsByID(id);
    }
}

And code to link in view :

@Html.ActionLink("more >>", "NewsInfo", "Home", new { id = news.Id });

The problem is when I start my web page link have format like :

http://localhost:52748/Home/NewsInfo?Length=4

Why Lenght = 4 ? To get it work for now i made code like this :

<a href="/home/[email protected]"> more >>  </a>

And it work proper but I want to use ActionLink so how to pass parameters there proper ? What is difference between those two methods. And last question this link display more >>; (with semicolon at end where it get from ?)

If answer is oblivious don't be angry i'm starting mvc thing

Thanks :)

Upvotes: 0

Views: 51

Answers (1)

Jason Evans
Jason Evans

Reputation: 29186

Try

@Html.ActionLink("more >>", "NewsInfo", "Home", new { id = news.Id }, null);

Adding null as the last parameter. I think I've seen this before, and adding null did the trick.

I'm not sure where the length comes from, but this is weird side-effect of having so many overloads for Html.ActionLink.

EDIT:

Ah, just found this:

Why does Html.ActionLink render “?Length=4”

Upvotes: 1

Related Questions