为什么在Asp.net MVC中发送过帐请求时,为什么没有任何价值?

问题描述

我已经尝试了几个小时,但是没有运气。

我有添加或编辑我的书的表格。 当我插入书籍信息并按sumbit时。我只有bookImage,没有别的。 当我从PostMan检查数据时,我看到除Book Image之外的所有值都是空的。

     public class BookController : Controller
{


    string apiUrl = "http://localhost:8080/";
    

    public async Task<ActionResult> Index()
    {
        List<Book> BookInfo = new List<Book>();
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri(apiUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage responseMessage = await client.GetAsync("api/books");
            if (responseMessage.IsSuccessStatusCode)
            {
                var BookResponse = responseMessage.Content.ReadAsStringAsync().Result;
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling = NullValueHandling.Ignore,MissingMemberHandling = MissingMemberHandling.Ignore
                };
                
                BookInfo = JsonConvert.DeserializeObject<List<Book>>(BookResponse,settings);
            }
            return View(BookInfo);
        }
    }

    public ActionResult AddOrEdit(long id = 0)
    {

        if(id == 0)
        {
            return View(new Book());
        }
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://localhost:8080/api/");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync("books" + id.ToString()).Result;
            return View(response.Content.ReadAsAsync<Book>().Result);                
        }
       
        
    }

    [HttpPost]
    public ActionResult AddOrEdit( Book book)
    {

        if (book.BookId == 0)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("http://localhost:8080/api/");
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                HttpResponseMessage response = client.PostAsJsonAsync("books",book).Result;

                TempData["SuccessMessage"] = "Employee saved successfully";
                
            }
        }

我正在从Spring Boot获得我的Rest Api。

这是表格

    @model BookShop_mvc.Models.Book
    @{
    ViewBag.Title = "AddOrEdit";
    }
    <div class="form-body">
    @using (Html.BeginForm())
{
    @Html.HiddenFor(model => model.BookId)

    <div class="form-group">

        @Html.LabelFor(model => model.BookTitle)
        @Html.EditorFor(model => model.BookTitle)
        @Html.ValidationMessageFor(model => model.BookTitle)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.BookAuthor)
        @Html.EditorFor(model => model.BookAuthor)
        @Html.ValidationMessageFor(model => model.BookAuthor)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.BookPages)
        @Html.EditorFor(model => model.BookPages)
        @Html.ValidationMessageFor(model => model.BookPages)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.BookDescription)
        @Html.EditorFor(model => model.BookDescription)
        @Html.ValidationMessageFor(model => model.BookDescription)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.BookIsbn)
        @Html.EditorFor(model => model.BookIsbn)
        @Html.ValidationMessageFor(model => model.BookIsbn)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.bookImageContentType)
        @Html.EditorFor(model => model.bookImageContentType)
        @Html.ValidationMessageFor(model => model.bookImageContentType)
    </div>
    <div class="form-group">

        @Html.LabelFor(model => model.BookPrice)
        @Html.EditorFor(model => model.BookPrice)
        @Html.ValidationMessageFor(model => model.BookPrice)
    </div>

    <div class="form-group">
        <input type="submit" value="Submit" class="btn button" />
        <input type="reset" value="Reset" class="btn button" />
    </div>
}
        @section scripts{
    @Scripts.Render("~/bundles/jqueryval")
      }

当我点击Submit时,我是邮递员,我没有任何价值

this is postman that all the values are null

,这是我重新索引最近2本书的索引时没有图像的网站

as you can see the last 2 books does not have any name,price,description

解决方法

解决了

我只需要更改变量名,而不是BookId-> bookId和Bookauthor-> bookAuthor

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...