'List not beign assigned as a parameter Url.Action
I'm using Url.Action to pass some paramenters to a method, like this
//Sending data
<a href="@Url.Action("BorrarMensaje", "Supplier", new { idMsg = item.IDMensaje, idMsgUsr = item.IDMensajeUsuario, idImg = item.IDImagen, idsArchs = item.IDArchivos })" class="btn btn-danger">Sí</a>
//Method
public ActionResult BorrarMensaje(int idMsg, int idMsgUsr, int idImg, List<int> idsArchs)
{
tblMensaje tblMensaje = db.tblMensaje.Find(idMsg);
tblMensajesUsuario tblMensajesUsuario = db.tblMensajesUsuario.Find(idMsgUsr);
tblImagenAdj tblImagenAdj = db.tblImagenAdj.Find(idImg);
foreach (var id in idsArchs)
{
tblArchivoAdj tblArchivoAdj = db.tblArchivoAdj.Find(id);
db.tblArchivoAdj.Remove(tblArchivoAdj);
}
//Some more code...
The values of idMsg, idMsgUsr, idImg are sent as arguments, but idsArch just doesn´t get the value of IDArchivos, when I view the count property it shows 0, (both idsArch and IDArchivos are of type List), I don't know why it isn't working, is there any alternative to do this? Thanks beforehand
Solution 1:[1]
For alternatives; you could write it as a Form and fields are hidden.
<form method="GET" action="@Url.Action("BorrarMensaje", "Supplier")">
<input name="idMsg" value="@item.IDMensage" hidden />
<input name="idMsgUsr" value="@item.IDMensajeUsuario" hidden />
<input name="idImg" value="@item.IDImagen" hidden />
<!-- for type list, you need to loop and specify an index -->
@for(int i = 0; i < item.IDArchivos.Count(); i++){
<!--replace PropertyName with the property name of IDArchivos that you want to submit -->
<input name="idsArchs[@i].PropertyName" hidden />
<input class="btn btn-danger" type="Submit" value="Si">
}
</form>
No changes in controller.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jerdine Sabio |
