• HTML赋值方法练习


    index.cshtml

    @{
        ViewBag.Title = "Index";
    }
    @model TestHtmlMethod2.Models.Genre
    <h2>Index</h2>
    <div>
        @Html.TextBox("Title", "")<text>这是一个text框</text>
        @Html.TextArea("Desc","描述<br/>",10,80,null)<text>这是一个文本域</text>
        @Html.Label("Desc", "显示文字")
        @*
            @Html.TextBoxFor(m => m.GenreId)
            @Html.LabelFor(m=>m.GenreId)<text>自动的查找当前模型中是否有GenreId这个属性,如果有这个属性那么就查询是否有设置固定的显示名称,有设置显示名称就显示出来。</text>
        </div>
        <div>
            @Html.ValidationMessage("Title")<text>显示后台输出的错误</text>
            @Html.PasswordFor(m => m.GenreId)*@
        @Html.RadioButtonFor(m => m.GenreId,"1")@Html.LabelFor(m => m.GenreId,"颜色")
        @Html.ActionLink("回到产品首页", "Index", "Product", new {id="1" },null)<text>传递一个参数过去</text>
        @Html.RouteLink("返回", new { action = "Index" })<text>跟ActionLink遵循相同的模式</text>
        @Url.Action("Browse", "Store", new { grenre = "Jazz" },null)<text>返回URL路径</text>
        @Html.Partial("View")<text>只把部分视图的内容渲染成字符串不会执行操作方法</text>
        @{Html.RenderPartial("View");}<text>跟上面一个方面效果一样,都是写入到http流中,但是这个在高流量的网站中性能更好</text>
        @Html.Action("ActionView2") <text>获得动作返回的结果,然后输入到http流中</text>
        @{Html.RenderAction("ActionView2");}
    </div>

    HomeController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace TestHtmlMethod2.Controllers
    {
        public class HomeController : Controller
        {
            // GET: Home
            public ActionResult Index()
            {
                ModelState.AddModelError("Title","标题不能为空!");
                ModelState.AddModelError("Name","名称不能为空!");
                ViewBag.Price = 10.00;
                Models.Genre mg = new Models.Genre();
                return View(mg);
            }
            public ActionResult View()
            {
                ViewBag.Name = "名称";
                return View();
            }
            [ChildActionOnly]//只能通过html.action方法或者renderAction方法来调用,直接访问无效
            [ActionName("ActionView2")]//使用自定义的访问名称
            public string View2()
            {
                return "Action方法调用返回的值";
            }
        }
    }
  • 相关阅读:
    DHCP分配ip地址。0.0.0.0与255.255.255.255
    net-snmp配置文件详解
    net-snmp开发中出现“Error opening specified endpoint"" ”的解决方案
    Elasticsearch 学习笔记
    Prometheus 监控报警系统 AlertManager 之邮件告警
    Match All Query
    Elasticsearch postman
    Centos7修改root密码
    ElasticSearch中profile API的使用
    kafka查询某时间段内的消息
  • 原文地址:https://www.cnblogs.com/frank888/p/4559715.html
Copyright © 2020-2023  润新知