我的asp.net应用程序出了问题。这是我的index.html
@using BricksBreaking;
@model FieldModel
@{
ViewData["Title"] = "Game";
}
<h2>Index</h2>
<table class="field">
@for (int row = 0; row < Model.Field.RowCount; row++)
{
<tr>
@for (int column = 0; column < Model.Field.ColumnCount; column++)
{
var tile = Model.Field.Tiles[row, column];
if (tile == null)
{
<td />
}
else
{
if (Model.Field.Tiles[row, column].Color == TileColor.Red) {
<td>
<a href='/BricksBreaking/Click?r=@row?c=@column'>
<img src='/images/cervena.png' />
</a>
</td>
}if(Model.Field.Tiles[row, column].Color == TileColor.Yellow)
{
<td>
<a href='/BricksBreaking/Click?r=@row?c=@column'>
<img src='/images/zlta.png' />
</a>
</td>
}if(Model.Field.Tiles[row, column].Color == TileColor.Blue)
{
<td>
<a href='/BricksBreaking/Click?r=@row?c=@column'>
<img src='/images/modra.png' />
</a>
</td>
}
}
}
</tr>
}
</table>
&#13;
这是我的控制器
public class BricksBreakingController : Controller
{
ScoreServiceDatabase scoreService = new ScoreServiceDatabase();
public IActionResult Index()
{
var field = new Field(9, 9, 5);
HttpContext.Session.SetObject("field", field);
var model = new FieldModel
{ Field = field, Scores = scoreService.GetTopScores() };
return View(model);
}
public IActionResult Click(int r, int c)
{
var field = HttpContext.Session.GetObject("field") as Field;
field.ClickTile(r,c);
HttpContext.Session.SetObject("field", field);
var model = new FieldModel
{ Field = field, Scores = scoreService.GetTopScores() };
return View("Index", model);
}
}
}
&#13;
问题是。总是在这一行
<a href='/BricksBreaking/Click?r=@row?c=@column'>
传递给控制器中的函数单击的参数始终为0.无论我是否写了类似这样的内容
<a href='/BricksBreaking/Click?r=2?c=2'>
总会有0。
有人可以帮我这个吗?我是.NET的新手。
答案 0 :(得分:1)
您只需要在第一个参数之前写一个?
。第一个参数之后的每个参数都需要&
<a href='/BricksBreaking/Click?r=2&c=2'>