开发者

Best approach for creating image buttons in MVC 2

I am writing a questionnaire application with ASP.NET MVC 2.

I have a set of questions that require a response of yes, no, unsure.

These need to be images that return a value to the quest开发者_如何学JAVAionnaire controller.

What is the best approach for adding image buttons?


I'd go with creating an ImageButton HtmlHelper.

http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs


This is long path of misery, where you will encounter IE differences from firefox, outrageous numbers of forms, image maps, violating HTTP with using image links instead.

Take it from me, save the fruitless journey: Use a regular button and use CSS to style in the image.

Give your buttons a name and a value:

<input type="submit" name="submitButton" value="Yes" class="YesImage" />
<input type="submit" name="submitButton" value="No" class="NoImage" />

Then in your controller:

[HttpPost]
public ActionResult Something(string submitButton)
{
    switch (submitButton)
    {
        case "Yes":
            //do something
            break;
        case "No":
            //do something else
            break;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜