RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-247158

Adrian's questions

Martin Hope
Adrian
Asked: 2020-08-23 02:45:06 +0000 UTC

关于引用数据类型的问题

  • 9

如果string是引用类型,比如 and class,那么为什么 ystr1和有str2不同的值呢?理论上,两个变量都应该引用堆上的同一个内存区域,country1以及country2

static void Main(string[] args)
{
    Country country1 = new Country();
    country1.x = 1;
    country1.y = 2;

    Console.WriteLine("Country1 {0}, {1}", country1.x, country1.y);

    Country country2 = new Country();
    country2 = country1;
    country1.x = 3;

    Console.WriteLine("Country1 {0}, {1}", country1.x, country1.y);
    Console.WriteLine("Country2 {0}, {1}", country2.x, country2.y);
    ///////////////////
    string str1;
    str1 = "123";

    Console.WriteLine("Str1 {0}", str1);

    string str2;
    str2 = str1;
    str1 = "1234";

    Console.WriteLine("Str1 {0}", str1);
    Console.WriteLine("Str2 {0}", str2);
}

在此处输入图像描述

c#
  • 3 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-29 03:18:31 +0000 UTC

解释 Visual Studio 如何处理数据库

  • 0

我在 , 上有一个Visual Studio项目。默认情况下,在项目中创建了一个本地数据库。服务器资源管理器说数据源是. 仅适用于或者如果你愿意,你可以连接到另一个 subd?请解释这一切是如何运作的,它不会让我休息。c#web-приложение asp.netMicrosoft SQL ServerVisual StudioMicrosoft SQL Server

база-данных
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-14 22:15:28 +0000 UTC

您需要将一个值传递给脚本,但是使用 div 加载不起作用

  • 0

您需要将一个值传递给脚本,但它不适onload用于div.

<div onload="myfunc(this)" data-passed-perc="@passed_perc"></div>
asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-14 14:41:35 +0000 UTC

DropDownListFor 不选择值

  • 3

如何使DropDownListForin 中的值显示在中SelectedStatusId?现在显示一行中的第一个,无论值如何SelectedStatusId

在控制器中

List<SelectListItem> Statuses = new List<SelectListItem>();
Statuses.Add(new SelectListItem() { Text = "Passed", Value = "PSS" });
Statuses.Add(new SelectListItem() { Text = "Failed", Value = "FL" });
Statuses.Add(new SelectListItem() { Text = "Blocked", Value = "BLCK" });
Statuses.Add(new SelectListItem() { Text = "Not run", Value = "NR" });

ViewBag.Statuses = new SelectList(Statuses, "Value", "Text");

在视野中

@Html.DropDownListFor(
x => x.SelectedStatusId,
(SelectList)ViewBag.Statuses,
new { @class = "form-control" }
)
asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-08 23:34:46 +0000 UTC

如何使用从一个模型到另一个模型的数据?

  • 0

我有两张桌子

public class TestManagementToolsContext : DbContext
{
    public DbSet<Test_Case> Test_Cases { get; set; }
    public DbSet<Test_Suite> Test_Suites { get; set; }
}

如何在模型中使用 in Test_Suite Test_Cases?

当我向 中添加一个列表List<Test_Case>时Test_Suite,当这个带有案例的列表发生变化时,案例也会发生变化Test_Cases

    public ActionResult Create()
    {

        var query = db.Test_Cases
            .Include(c => c.StepAndExpResults)
            .AsNoTracking()
            .ToList()
            .Select(c => new Test_Case
        {
            Identifier = c.Identifier,
            Title = c.Title,
            Preconditions = c.Preconditions,
            Date = c.Date,
            Comments = c.Comments,
            Summary = c.Summary,
            StepAndExpResults = c.StepAndExpResults
        }).ToList();

        Test_Suite suite = new Test_Suite();

        suite.all_test_cases = query;

        return View(suite);
    }

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "Id,Name,Description,test_cases_ch,all_test_cases,Date")] Test_Suite test_Suite)
    {
        if (ModelState.IsValid)
        {
            int count = 0;
            for (int i = 0; i < test_Suite.all_test_cases.Count; i++)
            {
                if (test_Suite.all_test_cases[i].check == true)
                {
                    //test_Suite.all_test_cases[i].check = false;

                    if (test_Suite.test_cases_ch == null)
                    {
                        test_Suite.test_cases_ch = new List<Test_Case>();
                    }
                    Test_Case test_case = new Test_Case();
                    test_Suite.test_cases_ch.Add(test_case);
                    test_Suite.test_cases_ch[count] = test_Suite.all_test_cases[i];
                    count++;
                }
            }
            test_Suite.Date = DateTime.Now;
            test_Suite.all_test_cases = null;
            db.Test_Suites.Add(test_Suite);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        return View(test_Suite);
    }
asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-08 17:44:31 +0000 UTC

如何获取数据库中元素的副本?

  • 1

我有两个模型。测试用例和一组测试用例,Test_Case并且,Test_Suite相应地,以及,Test_Suite包括一个列表Test_Case

当我得到这样的测试用例时:

Test_Suite suite = new Test_Suite();
suite.all_test_cases = db.Test_Cases.ToList();

那么所有的操作suite.all_test_cases都会影响db.Test_Cases

如何让Test_Suite所有的测试用例都进入模型,让它们不相连?我明白这是问题所在

asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-04 17:49:16 +0000 UTC

@Html.DisplayFor -- 额外的空行和空白字符

  • 0

视图中有一段代码:

<td style="word-wrap:break-word; white-space:pre-line">
    @Html.DisplayFor(model => Model.Checks[i].Value)
</td>

这个案例是这样呈现的: 一

问题:如何去除文本前的空行?都已经筋疲力尽了。

PS 随着white-space:pre-wrap更多的空白字符出现,它看起来像这样: 2个

html
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-05-02 20:38:10 +0000 UTC

将数据从局部视图传递到按钮上的控制器

  • 1

在“创建”页面上,我使用局部视图来动态添加文本框。这是实现:

创建.cshtml

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

    <table>
        <tr>
            <th colspan="3">Checks</th>
        </tr>
        <tbody id="tableCheck">
            @Html.Partial("_checklist")
        </tbody>
    </table>

    <input type="button" value="Add check" id="addCheck" />
}

脚本

$(function () {
    $("#addCheck").click(function () {
        $.ajax({
            type: "POST",
            url: '/Checklists/GenerateChecks',
            data: $(this).closest("form").serialize(),
            success: function (html) {
                $('#tableCheck').html(html);
            },
            error: function (msg) {
                console.log(msg);
            }
        });
    });
});

好吧,部分视图本身 _checklist.cshtml,列表中的每个项目都有删除按钮。在按钮上,我试图在 DeleteCheck 方法中将事物的 ID 和模型本身传递给控制器​​。

@model TestManagementTools.Models.Checklist

@if (Model != null) {
    for (int i = 0; i < Model.Checks.Count; i++)
    {
        <tr>
            <td>
                @(i + 1)
            </td>
            <td>
                @Html.TextAreaFor(model => model.Checks[i].Value, new { @class = "form-control" })
            </td>
            <td>
                //пробуем передать
                <a href="@Url.Action("DeleteCheck", "Checklists", new { checklist = Model, id = Model.Checks[i].Id })" role="button">Delete</a>
            </td>
        </tr>
    }   
}

实际上,这里是ChecklistsController.cshtml控制器中的方法。

//добавление проверки по кнопке
[HttpPost]
public ActionResult GenerateChecks(Checklist checklist)
{
    if (Request.IsAjaxRequest())
    {
        Check check = new Check();

        if (checklist.Checks == null)
        {
            checklist.Checks = new List<Check>();
        }

        checklist.Checks.Add(check);

        return PartialView("_checklist", checklist);
    }
    return PartialView("_checklist", checklist);
}

//удаление проверки, но сюда приходит модель равная null
public ActionResult DeleteCheck(int id, Checklist checklist)
{
    checklist.Checks.RemoveAt(id);
    return PartialView("_checklist", checklist);
}

所以问题是如何将事物和模型 ID 从我的局部视图传递到控制器?现在,如上所述,变为空

asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-04-28 04:37:26 +0000 UTC

列表未保存到数据库[重复]

  • 0
这个问题已经在这里得到回答:
如何使用 EF 获取相关对象? (2 个答案)
5 年前关闭。

我创建了一个清单,添加到数据库中:

创造

我从数据库中读取 - 列表是空的,其他一切都已到位:

细节

模型

public class Checklist
{
    public int Id { get; set; }

    public List<Check> Checks { get; set; }
}

public class Check
{
    public int Id { get; set; }

    public string Value { get; set; }
} 

控制器

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "Id,Checks")] Checklist checklist)
{
    if (ModelState.IsValid)
    {
        db.Checklists.Add(checklist);
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    return View(checklist);
}


public ActionResult Details(int? id)
{
    if (id == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }
    Checklist checklist = db.Checklists.Find(id);
    if (checklist == null)
    {
        return HttpNotFound();
    }
    return View(checklist);
}
asp.net
  • 1 个回答
  • 10 Views
Martin Hope
Adrian
Asked: 2020-04-27 02:50:17 +0000 UTC

未调用控制器方法

  • 1

模型

public class Checklist
{
    public int Id { get; set; }

    public Check Check { get; set; }

    public List<Check> Checks { get; set; }
}

public class Check
{
    public int Id { get; set; }

    public string Value { get; set; }
} 

ChecklistsController.cs控制器方法

[HttpPost]
public ActionResult GenerateChecks(Checklist checklist)
{
    if (Request.IsAjaxRequest())
    {
        Check check = new Check();
        check.Value = checklist.Check.Value;

        if (checklist.Checks == null)
        {
            checklist.Checks = new List<Check>();
        }

        checklist.Checks.Add(check);

        return PartialView("_checklist", checklist);
    }
    return PartialView("_checklist", checklist);
}

创建.cshtml 视图

<script src="@Url.Content("~/Scripts/add_check.js")" type="text/javascript"></script>

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

    <h4>New Checklist</h4>

    <table class="table table-bordered" id="tableCheck">
        <tr><th>Checks</th></tr>
        <tbody></tbody>
    </table>

    <input type="button" value="Add" class="btn btn-default" id="addCheck" />

    <input type="submit" value="Create" class="btn btn-primary" />
}

添加检查.js

$(function () {
    $("#addCheck").click(function () {
        $.ajax({
            type: "POST",
            url: 'Checklists/GenerateChecks',
            data: form.serialize()
        })
        .success(function (html) {
            var tableBody = document.getElementById('tableCheck').getElementsByTagName('tbody')[0];
            tableBody.text(html);
        })
        .error(function (msg) {
            console.log(msg);
        });
    });
});

_checklist.cshtml的部分视图

@model TestManagementTools.Models.Checklist

@for (int i = 0; i < Model.Checks.Count; i++)
{
    <tr>
        <td>
            @Html.TextBoxFor(model => model.Checks[i].Value, new { @class = "form-control" })
        </td>
    </tr>
}
javascript
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5