要自定义样式的单选列表框,可以使用Asp.Net Razor的Html.DropDownListFor方法,并在视图文件中添加样式。
以下是一个示例解决方法:
@using YourProjectName.Models
@model YourModel
@{
ViewBag.Title = "Custom Style Radio Button List";
}
@Html.DropDownListFor(model => model.SelectedOption, Model.OptionsList, new { @class = "custom-style" })
.custom-style {
/* Add your custom styles here */
}
using System.Collections.Generic;
using System.Web.Mvc;
using YourProjectName.Models;
namespace YourProjectName.Controllers
{
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new YourModel();
model.OptionsList = GetOptionsList();
return View(model);
}
private List GetOptionsList()
{
var optionsList = new List
{
new SelectListItem { Text = "Option 1", Value = "1" },
new SelectListItem { Text = "Option 2", Value = "2" },
new SelectListItem { Text = "Option 3", Value = "3" }
};
return optionsList;
}
}
}
确保将"YourProjectName"和"YourModel"替换为您的项目名称和模型名称。
通过按照上述步骤进行操作,您将能够使用自定义样式创建Asp.Net Razor单选列表框。