本文介绍了如何使用相同的userid和customerid更新记录中的referance表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个参考表,当用户通过Trigger自动创建它时,会使用userId放置一条记录。当客户添加公司信息时,我想使用CustomerId更新该记录。在其下面(private readonly int CustomerId),它的消息显示为:

字段'CustomerController.CustomerId'永远不会被赋值,并且将始终具有其默认值0



所以也许它正在用0更新记录。我无法分辨,因为在使用触发器创建记录时我在列中放置了一个零,因为我将它们设置为非null。

感谢您的帮助。



我的尝试:



控制器:

I have a reference table that when a user is created it automatically, by Trigger, puts a record with the userId. When a Customer adds Company info I would like to update that record with CustomerId. Below where (private readonly int CustomerId) is this has a message that reads:
Field 'CustomerController.CustomerId' is never assigned to, and will always have its default value 0

So perhaps it is updating the record with 0. I cannot tell because on record creation with the trigger I put a zero in the columns as I have them set to not null.
Thank you for your help.

What I have tried:

Controller:

private readonly int CustomerId;
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult CreateProfile([Bind(Include = "CustomerId,CustomerName")] CustomerNames customerNames)
        {
            if (ModelState.IsValid)
            {
                db.CustomerNames.Add(customerNames);
                var user = User.Identity.GetUserId();
                var companyId = (from p in db.UserJoin where p.UserId == user select p).First();
                companyId.CustomerId = CustomerId;
                db.SaveChanges();
                return RedirectToAction("AddBillingAddress", "BillingAddresses");
            }

            return View(customerNames);
        }







型号:






Model:

public class UsersToAddresses
{
    [Key]
    public string UserId { get; set; }
    public int BillToId { get; set; }
    public int ShipToId { get; set; }
    public int CustomerId { get; set; }
}

推荐答案

private readonly int CustomerId = 0;


这篇关于如何使用相同的userid和customerid更新记录中的referance表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:59