I want to use Repeater control in MVC3 razor. Having sheet in which middle section of sheet changes while upper portion and lower portion remains the same for all sheet.
This is genera;l requirement of invoice. How could I do so using repeater. If someone having other way I can try it too.
No..you cannot use server side controls in asp.net mvc ,you can only use html tags or html helpers,in order to achieve repeater control functionality you have to use foreach loop's like given below :
foreach(var item in Model.List)
{
<img src='@Url.Content("~/controller/action/" + item)' />
}
OR You can also use :
You can use @Html.EditorFor() or DisplayFor with an Editor/Display Template.
Items class:
public class Items
{
public int Id { get; set; }
public string Name { get; set; }
public List<Items> Itemlst { get; set; }
}
Controller:
public ActionResult List()
{
Items itemobj = new Items();
itemobj.Itemlst = //bind list of items here
return View(itemobj);
}
And in my view I would have the following:
<table>
@foreach(var item in Model.Itemlst)
{
<tr>
<td>Items Name:</td>
<td>@item.Name</td>
</tr>
}
</table>