4

I am new to asp.net, what I really want is to give a parameter to an ActionResult.

I want somtehing like this (I dont know if this is possible)

Sudoku s = new Sudoku(); // SudokuClass has a property -> public int[,] MyFields {get;set;} public ActionResult Index(int value) { if(value == 1) { myGame.Create(); s.MyFields = myGame.GameField(); } if(value == 2) { myGame.Cheat(); s.MyFields = myGame.GameField(); } if(value == 3) // some code return View(s); } 

MyCode is Index.cshtml

@Html.ActionLink("Cheat", "Index") 

What i want is: if I click on the actionlink "Cheat", that i can give number 2 so the Cheat Method will start, and update s.MyFields;

The other code for displaying the fields I have omitted. I can get the fields show on the webpage when I use s.MyFields = mygame.GetFields(). So thats not the problem, the problem is how can I "Update" this when I Click on cheat.

3
  • 2
    i cannot test it now, but it should be someting like: @Html.ActionLink("Cheat", "Index", new { value = 2 }) Commented Jan 4, 2016 at 20:48
  • 3
    possible duplicate: stackoverflow.com/questions/8293934/… Commented Jan 4, 2016 at 20:52
  • Thank you for answering! Commented Jan 4, 2016 at 21:04

1 Answer 1

2
@Html.ActionLink("Cheat", "Index", new { value = 2}) 

Or any number you want to pass from your View.

Sign up to request clarification or add additional context in comments.

2 Comments

I did not understand, what do you mean by "it makes a new HomeController"? Could you provide more details

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.