0

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/NewsInfo?id=@news.Id"> 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 :)

Aht
  • 583
  • 4
  • 25

1 Answers1

1

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”

Community
  • 1
  • 1
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
  • 1
    When I add it at end it start works thanks very much. This `lenght` is so strange but it dispirited now. :) – Aht Nov 21 '15 at 13:05