MVC Html.EditorFor文本框不渲染

时间:2018-10-25 20:34:25

标签: asp.net-mvc

Edit.cshtml

ffmpeg version 4.0.2-static https://johnvansickle.com/ffmpeg/  Copyright (c) 2000-2018 the FFmpeg developers
  built with gcc 6.3.0 (Debian 6.3.0-18+deb9u1) 20170516
  configuration: --enable-gpl --enable-version3 --enable-static --disable-debug --disable-ffplay --disable-indev=sndio --disable-outdev=sndio --cc=gcc-6 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-gray --enable-libaom --enable-libfribidi --enable-libass --enable-libvmaf --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-librubberband --enable-libsoxr --enable-libspeex --enable-libvorbis --enable-libopus --enable-libtheora --enable-libvidstab --enable-libvo-amrwbenc --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzimg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
Input #0, ogg, from '1_a.opus':
  Duration: 00:01:03.82, start: -0.020000, bitrate: 37 kb/s
    Stream #0:0: Audio: opus, 48000 Hz, stereo, fltp
Input #1, ogg, from '2_a.opus':
  Duration: 00:00:52.40, start: -0.020000, bitrate: 44 kb/s
    Stream #1:0: Audio: opus, 48000 Hz, stereo, fltp
Input #2, mov,mp4,m4a,3gp,3g2,mj2, from '1_v.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.12.100
  Duration: 00:01:03.85, start: 0.000000, bitrate: 2644 kb/s
    Stream #2:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 2633 kb/s, 333 fps, 333 tbr, 10656 tbn, 666 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Input #3, mov,mp4,m4a,3gp,3g2,mj2, from '2_v.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.12.100
  Duration: 00:00:52.32, start: 0.000000, bitrate: 861 kb/s
    Stream #3:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x480 [SAR 1:1 DAR 4:3], 860 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
Stream mapping:
  Stream #0:0 (opus) -> amix:input0
  Stream #1:0 (opus) -> adelay
  Stream #2:0 (h264) -> hstack:input0
  Stream #3:0 (h264) -> trim
  Stream #3:0 (h264) -> fifo
  amix -> Stream #0:0 (aac)
  hstack -> Stream #0:1 (libx264)
Press [q] to stop, [?] for help
[libx264 @ 0x6d21600] using SAR=1/1
[libx264 @ 0x6d21600] using cpu capabilities: MMX2 SSE2Fast SSSE3 Cache64 SlowShuffle
[libx264 @ 0x6d21600] profile Constrained Baseline, level 5.1
[libx264 @ 0x6d21600] 264 - core 155 r2901 7d0ff22 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=0 ref=1 deblock=0:0:0 analyse=0:0 me=dia subme=0 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=0 threads=3 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=0 intra_refresh=0 rc=crf mbtree=0 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=0
Output #0, mp4, to 'mayank_navid_bars_try2.mp4':
  Metadata:
    encoder         : Lavf58.12.100
    Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      encoder         : Lavc58.18.100 aac
    Stream #0:1: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x480 [SAR 1:1 DAR 8:3], q=-1--1, 333 fps, 10656 tbn, 333 tbc (default)
    Metadata:
      encoder         : Lavc58.18.100 libx264
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Past duration 0.999992 too large
    Last message repeated 12 times
More than 1000 frames duplicated   33280kB time=00:01:08.03 bitrate=4007.4kbits/s dup=982 drop=1590 speed=0.536x    
frame=22679 fps=177 q=-1.0 Lsize=   33892kB time=00:01:08.10 bitrate=4076.9kbits/s dup=1339 drop=1590 speed=0.531x    
video:32804kB audio:953kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.401324%
[aac @ 0x6d4c680] Qavg: 22255.799
[libx264 @ 0x6d21600] frame I:91    Avg QP:15.31  size: 51639
[libx264 @ 0x6d21600] frame P:22588 Avg QP:18.24  size:  1279
[libx264 @ 0x6d21600] mb I  I16..4: 100.0%  0.0%  0.0%
[libx264 @ 0x6d21600] mb P  I16..4:  0.2%  0.0%  0.0%  P16..4: 13.0%  0.0%  0.0%  0.0%  0.0%    skip:86.8%
[libx264 @ 0x6d21600] coded y,uvDC,uvAC intra: 44.9% 54.0% 29.9% inter: 2.0% 10.9% 0.1%
[libx264 @ 0x6d21600] i16 v,h,dc,p: 45% 24% 13% 18%
[libx264 @ 0x6d21600] i8c dc,h,v,p: 51% 20% 18% 11%
[libx264 @ 0x6d21600] kb/s:3945.79

TestModel.cs

@model MVCExercise.Models.User

@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Edit</h2>
<div>
    @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
</div>
<div>
    @Html.EditorFor(model => model.ID, new { htmlAttributes = new { @class = "form-control" } })
</div>

HomeController.cs

namespace MVCExercise.Models
{
    public class User
    {
        public string Greeting => "Hello User";
        public string Name { get; set; }

        public string ID { get; set; }
    }
}

表格中显示的数据:

enter image description here

在表的第一项上单击“编辑”后,我得到以下图像。仅model.ID在文本框中呈现。

Model.name文本框完全空白:

enter image description here

1 个答案:

答案 0 :(得分:0)

Edit.cshtml:

@model MVCExercise.Models.User

@{
    ViewBag.Title = "Edit";
}

<h2>Edit</h2>


@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>User</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.ID, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.ID, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.ID, "", new { @class = "text-danger" })
        </div>
    </div>


    <div class="form-group">
        @Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            <input type="submit" value="Save" class="btn btn-default" />
        </div>
    </div>
</div>
}

<div>
    @Html.ActionLink("Back to List", "Index")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

TestModel.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVCExercise.Models
{
    public class User
    {
        public string Greeting => "Hello User";
        public string Name { get; set; }

        public string ID { get; set; }
    }
}

UsersController.cs:

// POST: Users/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "ID,Name")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(user);
        }

表格中显示的数据

enter image description here

在表条目上单击“编辑”后:

enter image description here