asp.net - Combine link and button to one -
have @ code:
<div class="widget bg"> <h3>kategorier</h3> <ul> @using (html.beginform("bloghome", "home", formmethod.post)) { foreach (var grouping in model.categories.groupby(c => c)) { <li><a href="#">@group.key (@group.count())</a></li> <button value="@group.key" name="cat">click me</button> } } </ul> </div> this code gives me button submits controller..i link excecute method can rid of button. tips on how tp achive that?
edit:
//kategorierlist here list of strings getting looped through in view:
var listofcategories = new list<string>(); foreach (var item in lista) { listofcategories.add(item.choosencategory); } edit:
@using (html.beginform("bloghome", "home", formmethod.post, new { id = "form1" })) { foreach (var grouping in model.categories.groupby(c => c)) { <li><a href="#" onclick="document.getelementbyid('form1').submit()">@group.key (@group.count())</a></li> <input type="hidden" value="@group.key" name="cat" /> } }
give form id:
@using (html.beginform("bloghome", "home", formmethod.post, new { id = "form1" })) then set submit function onclick action anchor:
<a href="#" onclick="document.getelementbyid('form1').submit()">@group.key (@group.count())</a> and maintain old value button in input type=hidden:
<input type="hidden" value="@group.key" name="cat" /> asp.net
No comments:
Post a Comment